mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
Ssh examples addition/update. (#114)
* reset * reference/SshBasics: MT example with CoFor added. * reference/SshBasics: Cosmetics.
This commit is contained in:
parent
a4ec1ecd91
commit
5f2d0f4938
4 changed files with 40 additions and 0 deletions
36
reference/SshBasics/SFtpMT2.cpp
Normal file
36
reference/SshBasics/SFtpMT2.cpp
Normal 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.");
|
||||
});
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ file
|
|||
Tunnel.cpp,
|
||||
"Core MT examples" readonly separator,
|
||||
SFtpMT.cpp,
|
||||
SFtpMT2.cpp,
|
||||
ExecMT.cpp,
|
||||
"Misc. examples" readonly separator,
|
||||
PickSemantics.cpp,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue