arg_desc->SetUsageContext(
GetArguments().GetProgramBasename(),
"SFTP API sample");
51arg_desc->AddOptionalKey(
"expected-key",
"PUBLIC_KEY",
"Limit trust to specified (base64-encoded) public key",
CArgDescriptions::eString);
54arg_desc->AddFlag(
"ftp",
"Use FTP instead of SFTP");
55arg_desc->AddFlag(
"echo",
"Echo input data");
56arg_desc->AddFlag(
"stream-flags",
"Output stream state flags after each comand");
57arg_desc->AddFlag(
"update-known-hosts",
"Update known hosts (~/.ssh/known_hosts) if host is trusted (affects other SSH/SFTP clients!)");
58arg_desc->AddFlag(
"do-not-trust-new-host",
"Do not trust new (unknown) host");
59arg_desc->AddFlag(
"trust-changed-host",
"Trust host with changed public key");
66cout <<
"================================================================================\n";
68 if(!getline(is, line)) {
82 const auto& host = args[
"HOST"].AsString();
83 const autoecho = args[
"echo"].AsBoolean();
84 const auto flags= args[
"stream-flags"].AsBoolean();
85 auto&
input= args[
"input-file"].AsInputFile();
86unique_ptr<iostream> sftp_stream;
89 const auto& user = args[
"user"].HasValue() ? args[
"user"].AsString() :
"ftp"s;
90 const auto& password = args[
"password"].HasValue() ? args[
"password"].AsString() :
"none"s;
91sftp_stream = make_unique<CConn_FtpStream>(host, user, password, args[
"path"].AsString());
93CSFTP_Session::SParams params(host);
96params.SetUser(args[
"user"].AsString());
99 if(args[
"password"].
HasValue()) {
100params.SetPassword(args[
"password"].AsString());
103 if(args[
"update-known-hosts"].AsBoolean()) {
104params.SetFlag(CSFTP_Session::fUpdateKnownHosts);
107 if(args[
"do-not-trust-new-host"].AsBoolean()) {
108params.SetFlag(CSFTP_Session::fDoNotTrustNewHost);
111 if(args[
"trust-changed-host"].AsBoolean()) {
112params.SetFlag(CSFTP_Session::fTrustChangedHost);
115 if(args[
"expected-key"].
HasValue()) {
116params.SetExpectedKey(args[
"expected-key"].AsString());
119CSFTP_Session sftp_session(params);
120sftp_stream = make_unique<CSFTP_Stream>(sftp_session, args[
"path"].AsString());
126*sftp_stream << line << endl;
128 if(
auto cmd= string_view(line).substr(0, line.find(
' ')); (
cmd==
"STOR"sv) || (
cmd==
"APPE"sv)) {
129 if(!getline(
input, line)) {
134cout << line << endl;
137*sftp_stream << line;
141cout <<
"--------------------------------------------------------------------------------\n";
147 const autos = sftp_stream->rdstate();
148 auto l= [s](
auto f) {
return bool(s &
f); };
149cout <<
"bad="<<
l(ios_base::badbit) <<
", fail="<<
l(ios_base::failbit) <<
", eof="<<
l(ios_base::eofbit) << endl;
151sftp_stream->clear();
157 int main(
intargc,
const char* argv[])
virtual int Run()
Run the application.
virtual void Init()
Initialize the application.
virtual const CArgs & GetArgs(void) const
Get parsed command line arguments.
int AppMain(int argc, const char *const *argv, const char *const *envp=0, EAppDiagStream diag=eDS_Default, const char *conf=NcbiEmptyCStr, const string &name=NcbiEmptyString)
Main function (entry point) for the NCBI application.
virtual void SetupArgDescriptions(CArgDescriptions *arg_desc)
Setup the command line argument descriptions.
const CNcbiArguments & GetArguments(void) const
Get the application's cached unprocessed command-line arguments.
@ eInputFile
Name of file (must exist and be readable)
@ eString
An arbitrary string.
bool NcbiStreamCopy(CNcbiOstream &os, CNcbiIstream &is)
Copy the entire contents of stream "is" to stream "os".
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
bool s_GetCommandLine(istream &is, string &line, bool echo)
int main(int argc, const char *argv[])
static SLJIT_INLINE sljit_ins l(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4