Home » Developing U++ » U++ Developers corner » SFTP or full SSH2 support for U++? (Discussion about implementing the SSH2 protocol using libssh2)
Re: SFTP or full SSH2 support for U++? [message #46099 is a reply to message #45813] |
Sun, 06 March 2016 23:39 |
Oblivion
Messages: 1094 Registered: August 2007
|
Senior Contributor |
|
|
Hello guys,
A major update:
SSH package is re-written using the new version of AsyncQueue class which can utilize ordinary callbacks and lambdas, instead of the cumbersome VarArgs class. SSH package relies heavily on lambda functions, therefore it will require C++11. I believe it is much more elegant now, since it drastically simplifed the task and reduced the source code significantly. It is almost complete, and first release is at hand. (SFtp component, at least).
Below code snippet is taken from the new version of a simple download test app that concurrently downloads a number of jpg files from a well-known public Sftp test server. As you can see, unnecessary state tracking is removed:
struct Job {
SFtp sftp;
FileOut file;
int index;
};
Array<Job> jobs;
//........
const char *sftp_server = "demo.wftpserver.com";
const char *sftp_user = "demo-user";
const char *sftp_password = "demo-user";
const char *remote_path = "/download";
bool SFtpDownloader::ReadDir(Ssh::DirList& ls)
{
// We'll get the directory listing, using a synchronous (blocking) call.
SFtp browser;
browser.WhenDo << [&] {ProcessEvents(); }; // GUI should be responsive...
if(browser.Connect(sftp_server, 2222, sftp_user, sftp_password)) {
// Let us use a convenience method which works on paths, not file descriptors.
if(browser.ListDir(remote_path, ls))
return true;
}
Exclamation(browser.GetErrorDesc());
return false;
}
void SFtpDownloader::Download()
{
// Wait for the queue to be processed.
if(!jobs.IsEmpty())
return;
Ssh::DirList ls;
if(!ReadDir(ls))
return;
for(int i = 0, j = 0; i < ls.GetCount(); i++) {
// We can work on directory entries easily.
Ssh::DirEntry& e = ls[i];
const Ssh::Attrs& attrs = e.GetAttrs();
// Let us simply try to download all files with *.jpg extension to the current directory, asynchronously.
// Here, thanks to AsyncQueue, asynchronous calls work in a fire-and-forget fashion. Similar to "batch processing".
// E.g., any number of Sftp commands/jobs can be queued to be processed without intervention (till they're finished, or failed, of course).
if(attrs.IsFile() && GetFileExt(e.GetName()).IsEqual(".jpg")) {
Job& job = jobs.Add();
job.index = j;
job.file.Open(Format("%s/SFtpExample-%d-%s", GetHomeDirectory(), job.index, e.GetName()));
job.sftp.StartConnect(sftp_server, 2222, sftp_user, sftp_password);
job.sftp.StartGet(job.file, Format("%s/%s", remote_path, e.GetName()), Ssh::READ, 0755, THISBACK2(DownloadProgress, job.index, e.GetName()));
j++;
}
}
// Below loop does asynchronous job processing.
while(!jobs.IsEmpty()) {
int i = 0;
SocketWaitEvent we;
we.Add(jobs[i].sftp.GetSocket());
we.Wait(10);
while(i < jobs.GetCount()) {
SFtp& sftp = jobs[i].sftp;
sftp.Do();
if(!sftp.InProgress()) {
// For the sake of simplicity, we do not differentiate between success and failure.
jobs.Remove(i);
break;
}
ProcessEvents();
i++;
}
}
}
//........
Before I release the first public [beta] version, I'll have to write its docs. It'll probably happen this week.
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: Mon, 07 March 2016 08:36] 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: Thu May 16 13:12:26 CEST 2024
Total time taken to generate the page: 0.02042 seconds
|