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: 1136 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
|
|
|
|
|
SFTP or full SSH2 support for U++?
By: Oblivion on Sun, 10 January 2016 12:58
|
|
|
Re: SFTP or full SSH2 support for U++?
By: mirek on Sun, 10 January 2016 23:02
|
|
|
Re: SFTP or full SSH2 support for U++?
By: Oblivion on Mon, 11 January 2016 09:10
|
|
|
Re: SFTP or full SSH2 support for U++?
By: mirek on Mon, 11 January 2016 09:47
|
|
|
Re: SFTP or full SSH2 support for U++?
By: Oblivion on Tue, 26 January 2016 21:02
|
|
|
Re: SFTP or full SSH2 support for U++?
By: mirek on Sun, 31 January 2016 09:26
|
|
|
Re: SFTP or full SSH2 support for U++?
By: Oblivion on Mon, 01 February 2016 00:06
|
|
|
Re: SFTP or full SSH2 support for U++?
By: Oblivion on Sun, 06 March 2016 23:39
|
|
|
Re: SFTP or full SSH2 support for U++?
By: Tom1 on Sat, 13 May 2017 21:01
|
|
|
Re: SFTP or full SSH2 support for U++?
|
|
|
Re: SFTP or full SSH2 support for U++?
By: Tom1 on Sun, 14 May 2017 17:46
|
|
|
Re: SFTP or full SSH2 support for U++?
|
|
|
Re: SFTP or full SSH2 support for U++?
By: Tom1 on Wed, 28 June 2017 14:46
|
|
|
Re: SFTP or full SSH2 support for U++?
|
|
|
Re: SFTP or full SSH2 support for U++?
By: Tom1 on Wed, 28 June 2017 15:29
|
|
|
Re: SFTP or full SSH2 support for U++?
|
|
|
Re: SFTP or full SSH2 support for U++?
By: Tom1 on Wed, 28 June 2017 16:04
|
|
|
Re: SFTP or full SSH2 support for U++?
|
|
|
Re: SFTP or full SSH2 support for U++?
By: Tom1 on Sat, 01 July 2017 17:35
|
|
|
Re: SFTP or full SSH2 support for U++?
|
|
|
Re: SFTP or full SSH2 support for U++?
By: koldo on Sun, 02 July 2017 19:14
|
|
|
Re: SFTP or full SSH2 support for U++?
|
|
|
Re: SFTP or full SSH2 support for U++?
By: Tom1 on Sun, 02 July 2017 19:49
|
|
|
Re: SFTP or full SSH2 support for U++?
|
|
|
Re: SFTP or full SSH2 support for U++?
By: koldo on Mon, 03 July 2017 08:39
|
|
|
Re: SFTP or full SSH2 support for U++?
By: Tom1 on Mon, 03 July 2017 10:33
|
|
|
Re: SFTP or full SSH2 support for U++?
|
|
|
Re: SFTP or full SSH2 support for U++?
By: Tom1 on Tue, 04 July 2017 08:57
|
|
|
Re: SFTP or full SSH2 support for U++?
|
|
|
Re: SFTP or full SSH2 support for U++?
By: Tom1 on Tue, 04 July 2017 09:12
|
|
|
Re: SFTP or full SSH2 support for U++?
By: Oblivion on Sat, 12 August 2017 22:49
|
|
|
Re: SFTP or full SSH2 support for U++?
By: Tom1 on Mon, 14 August 2017 12:41
|
|
|
Re: SFTP or full SSH2 support for U++?
By: Oblivion on Mon, 14 August 2017 14:26
|
|
|
Re: SFTP or full SSH2 support for U++?
By: Tom1 on Mon, 14 August 2017 14:46
|
|
|
Re: SFTP or full SSH2 support for U++?
By: Oblivion on Mon, 14 August 2017 14:52
|
|
|
Re: SFTP or full SSH2 support for U++?
By: Tom1 on Mon, 14 August 2017 14:57
|
|
|
Re: SFTP or full SSH2 support for U++?
By: Oblivion on Sun, 15 October 2017 23:10
|
|
|
Re: SFTP or full SSH2 support for U++?
By: koldo on Mon, 16 October 2017 08:58
|
|
|
Re: SSH2 wrapper for U++
By: Oblivion on Thu, 19 October 2017 00:55
|
|
|
Re: SSH2 wrapper for U++
By: Tom1 on Thu, 19 October 2017 14:16
|
|
|
Re: SSH2 wrapper for U++
By: Oblivion on Thu, 19 October 2017 15:09
|
|
|
Re: SSH2 wrapper for U++
By: Tom1 on Mon, 23 October 2017 08:29
|
|
|
SSH package for U++ (alpha version)
By: Oblivion on Mon, 13 November 2017 21:25
|
|
|
Re: SFTP or full SSH2 support for U++?
|
|
|
Re: SFTP or full SSH2 support for U++?
By: Oblivion on Tue, 14 November 2017 08:38
|
|
|
Re: SFTP or full SSH2 support for U++?
|
|
|
Re: SFTP or full SSH2 support for U++?
By: Oblivion on Tue, 14 November 2017 12:41
|
|
|
Re: SFTP or full SSH2 support for U++?
By: Tom1 on Tue, 14 November 2017 14:27
|
|
|
Re: SFTP or full SSH2 support for U++?
By: Oblivion on Tue, 14 November 2017 21:51
|
Goto Forum:
Current Time: Sun Nov 10 20:41:02 CET 2024
Total time taken to generate the page: 0.00836 seconds
|