|
|
Home » Developing U++ » U++ Developers corner » SFTP or full SSH2 support for U++? (Discussion about implementing the SSH2 protocol using libssh2)
Re: SSH2 wrapper for U++ [message #48880 is a reply to message #48879] |
Thu, 19 October 2017 15:09 |
Oblivion
Messages: 1112 Registered: August 2007
|
Senior Contributor |
|
|
Hello Tom,
Quote:I downloaded this latest version now after using the version from a few months back.
In order to successfully compile the code, I had to comment out the entire contents of SFtpMT.cpp and the following lines in SFtp.h:
AsyncWork<String> SFtpGet(SshSession& session, const String& path, Gate<int64, int64> progress = Null);
AsyncWork<void> SFtpGet(SshSession& session, const String& source, const String& target, Gate<int64, int64> progress = Null);
Ah yes, that's because I use U++ trunk (latest nightly builds).
In case you didn't notice, there is now a class called AsyncWork in U++ core, which is a MT helper. Those functions use that.
Quote:
Then there's one question: Now that the names have changed, is there a replacement for session.IsSuccess() ? (I just removed these calls in my code to see if SFTP still works. It did Smile )
You don't need it. I got rid of the old ones. There is only IsError().
You can use the IsError() method to check success when it is necessary.
Did you look into the provided SFtpDemo app? Take a look into it. It demonstartes the basic usage pattern for SFtp (same pattern is valid for other components too)
If you use blocking mode, then you can simply check the return code (IsError will be still available though.)
In non-blocking mode, A successful operation means there is no error. So again, you can simply check IsError(), and then get the result with GetResult() method if the invoked method returns a value.
By the way, GetResult() method is needed in non-blocking mode for such methods as FileExists(), for we need to separate the state of operation (failure/success) from the return value of operation.
Non-blocking:
void GetFileSize(SshSession& session)
{
DLOG("---- Getting file size of " << file << " (non-blocking):");
auto sftp = session.CreateSFtp();
sftp.NonBlocking().GetSize(file);
while(sftp.Do())
Sleep(1);
if(sftp.IsError())
DDUMP(sftp.GetErrorDesc());
else
DDUMP((int64) sftp.GetResult()); // In non-blocking mode, results can be
// "harvested" using GetResult() method.
}
void FileExists(SshSession& session)
{
DLOG("---- Test if " << file << " exists (non-blocking):");
auto sftp = session.CreateSFtp();
sftp.NonBlocking().FileExists(file);
while(sftp.Do())
Sleep(1);
if(sftp.IsError())
DDUMP(sftp.GetErrorDesc());
else
DDUMP((bool) sftp.GetResult());
// Alternatively (blocking)
if(sftp.NonBlocking(false).FileExists(file))
Cout() << file << " exists.\n";
else
Cerr() << sftp.GetErrorDesc() << '\n';
}
.
Blocking:
DLOG("---- Downloading file " << file << " directly to Cout() (blocking):");
auto sftp = session.CreateSFtp();
if(!sftp.Get(file, Cout()))
DDUMP(sftp.GetErrorDesc());
else
DLOG("Done.");
Or
void GetDirectoryList(SshSession& session)
{
DLOG("---- Getting directory listing of " << dir << " (blocking):");
auto sftp = session.CreateSFtp();
SFtp::DirList list;
if(sftp.ListDir(dir, list)) {
for(auto& e : list)
DDUMP(e);
}
else DDUMP(sftp.GetErrorDesc());
}
I'll explain the details in documentation, but it is really very simple.
Note that I "removed" also the batch processing mode. This new version of SSH package can only process one request at a time. (well, from the user POV, at least. Basically it still uses a queue, but only internally, and in a well-determined way)
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Thu, 19 October 2017 16:05] Report message to a moderator
|
|
|
Re: SSH2 wrapper for U++ [message #48886 is a reply to message #48880] |
Mon, 23 October 2017 08:29 |
Tom1
Messages: 1242 Registered: March 2007
|
Senior Contributor |
|
|
Hi Oblivion,
Thanks for explaining the new details. I did not read the SFtpDemo this time, since I had already implemented client calls in my own software. So in effect I was just updating the SFTP code to its latest version. I should have paid more attention to the changes.
Anyway, thanks for the update! I'll let you know if I run into any trouble with it.
Best regards,
Tom
|
|
|
SSH package for U++ (alpha version) [message #48964 is a reply to message #45813] |
Mon, 13 November 2017 21:25 |
Oblivion
Messages: 1112 Registered: August 2007
|
Senior Contributor |
|
|
Hello,
SSH package is updated.
This version is the first "alpha" release.
This version brings,
- Multithreading support for SFtp, Scp, and SshExec classes.
- Ssh agent authentication support.
- SocketWaitEvents support for non-blocking I/O
- Ssh known hosts support (re-added).
- API documentation (updated)
- SFtp::DirEntry class gained ToXml() method.
- Keyboard (challenge/response) authentication (re-added)
- Updated libssh2
- Various bugfixes
I will soon add SshShell support. In fact there is already a prototype of SshShell for Posix based OSes. It can execute remote commands in real-time, and allows using editors such as nano, vim, emacs on console. It also works with GUI. I will add it once I clean its source code.
However, adding shell support on windows is somewhat tricky (at least, adding a console (CLI) based version is not so trivial, for standard I/O handling is different on windows. I need to find a reliable way before I can include it in the pacakge, so it'll take some time...)
I set up a GIT repo some time ago, where you can find the latest versions of my public U++ packages:
https://github.com/ismail-yilmaz/upp-components/tree/master/ Core/SSH
Below you can find the latest package. (I will open a Bazaar topic from the next release on, and update the package regularly.)
It is tested on Linux and Windows (GCC/MINGW 7.2, MSC 14 (2017)).
Suggestions, criticism, bug reports, reviews, testing is always welcome,
Cheers!
Oblivion
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Mon, 13 November 2017 21:32] Report message to a moderator
|
|
|
|
Re: SFTP or full SSH2 support for U++? [message #48968 is a reply to message #48967] |
Tue, 14 November 2017 08:38 |
Oblivion
Messages: 1112 Registered: August 2007
|
Senior Contributor |
|
|
Quote:
alkema_jm
index.php?t=getfile&id=5432&private=0LS,
I use upp-win-11459.7z, vs2017 and Windows10 , I downloaded https://svn.code.sf.net/p/ultimatecomponents/svn/, I put the trunk directories in the bazaar directory.
IpAddrInfo addrinfo;
Error is that the variable 'addrinfo' is a type/structure in Ultimate. To solve error, is renaming variable 'addrinfo' in something else for example 'addrinfo2'.
Hello alkema_jm,
Thank you for notifiying me about the issue.
SVN repo is not yet updated. SSH package in SVN repo is outdated. I will update it tonight.
https://github.com/ismail-yilmaz/upp-components/tree/master/ Core/SSH
However, the name clash you've mentioned is already fixed in the GIT version above.
Note that the new version is not entirely compatible with the old one. I suggest you update to it.
It is a re-write with a much better design with a ton of bug-fixes and new features. (Transition should be fairly easy though),
Ps.My previous message also includes the latest zip file which contains an example code demonstrating the basic usage of the latest SSH package. You may want to chech that too.
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Tue, 14 November 2017 08:45] Report message to a moderator
|
|
|
|
|
|
|
Goto Forum:
Current Time: Fri Sep 20 08:24:02 CEST 2024
Total time taken to generate the page: 0.03322 seconds
|
|
|