From 534f80a85f0fc87e8933b9f421f9360bfd38bf6f Mon Sep 17 00:00:00 2001 From: oblivion Date: Sun, 12 Aug 2018 22:04:11 +0000 Subject: [PATCH] Added a console-based SshExec example. git-svn-id: svn://ultimatepp.org/upp/trunk@12165 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- reference/SshExec/SshExec.cpp | 27 +++++++++++++++++++++++++++ reference/SshExec/SshExec.upp | 12 ++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 reference/SshExec/SshExec.cpp create mode 100644 reference/SshExec/SshExec.upp diff --git a/reference/SshExec/SshExec.cpp b/reference/SshExec/SshExec.cpp new file mode 100644 index 000000000..60923a0d9 --- /dev/null +++ b/reference/SshExec/SshExec.cpp @@ -0,0 +1,27 @@ +#include +#include + +using namespace Upp; + +CONSOLE_APP_MAIN +{ + StdLogSetup(LOG_COUT|LOG_FILE); +// Ssh::Trace(); + + const char *cmd = "ls -l /pub/example"; + String cout, cerr; + + SshSession session; + if(session.Timeout(30000).Connect("demo:password@test.rebex.net:22")) { + SshExec exec = session.CreateExec(); + if(exec(cmd, cout, cerr) >= 0) { + LOG("Stdout:\n" << cout); + LOG("Stderr:\n" << cerr); + LOG("Exit code: " << exec.GetExitCode()); + } + else + LOG(exec.GetErrorDesc()); + } + else + LOG(session.GetErrorDesc()); +} diff --git a/reference/SshExec/SshExec.upp b/reference/SshExec/SshExec.upp new file mode 100644 index 000000000..f68084d35 --- /dev/null +++ b/reference/SshExec/SshExec.upp @@ -0,0 +1,12 @@ +description "Demonstrates basic SSH remote command execution .\377"; + +uses + Core, + Core/SSH; + +file + SshExec.cpp; + +mainconfig + "" = ""; +