Ssh examples addition/update. (#114)

* reset

* reference/SshBasics: MT example with CoFor added.

* reference/SshBasics: Cosmetics.
This commit is contained in:
İsmail Yılmaz 2022-12-11 14:35:58 +03:00 committed by GitHub
parent a4ec1ecd91
commit 5f2d0f4938
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 0 deletions

View file

@ -0,0 +1,36 @@
#include "SshBasics.h"
// SFtpAsyncGet2: Demonstrates multiple file downloads, using a parallelization loop.
void SFtpAsyncGet2(SshSession& session)
{
const int MAXDOWNLOADS = 4;
const char *path = "/pub/example/";
SFtp::DirList ls;
{
// Get a remote dir listing.
SFtp browser(session);
if(!browser.ListDir(path, ls)) {
RLOG(browser.GetErrorDesc());
return;
}
}
// Filter the dir list.
auto files = FilterRange(ls, [](const SFtp::DirEntry& e) { return e.IsFile() && e.GetSize() <= 65536; });
// Loop over.
CoFor(min(files.GetCount(), MAXDOWNLOADS), [&files, &path, &session](int i){
const SFtp::DirEntry& e = files[i];
String fpath = AppendFileName(path, e.GetName());
RLOG("Downloading " << fpath);
SFtp sftp(session);
String file = sftp.LoadFile(fpath);
if(sftp.IsError())
RLOG(Format("Worker #%d: %s", sftp.GetId(), sftp.GetErrorDesc()));
else
RLOG("File " << e.GetName() << " is successfully downloaded.");
});
}

View file

@ -10,6 +10,7 @@ void SFtpGet(SshSession& session);
void SFtpStreamGet(SshSession& session);
void SFtpTransparency(SshSession& session);
void SFtpAsyncGet(SshSession& session);
void SFtpAsyncGet2(SshSession& session);
void ExecListDir(SshSession& session);
void ExecAsyncListDir(SshSession& session);
void ShellConsole(SshSession& session);

View file

@ -18,6 +18,7 @@ file
Tunnel.cpp,
"Core MT examples" readonly separator,
SFtpMT.cpp,
SFtpMT2.cpp,
ExecMT.cpp,
"Misc. examples" readonly separator,
PickSemantics.cpp,

View file

@ -42,6 +42,8 @@ CONSOLE_APP_MAIN
SFtpTransparency(session);
#elif defined(SSH_SFTP_MT)
SFtpAsyncGet(session);
#elif defined(SSH_SFTP_MT_LOOP)
SFtpAsyncGet2(session);
#elif defined(SSH_EXEC)
ExecListDir(session);
#elif defined(SSH_EXEC_MT)