PocoSSH

I’m currently in the process of pocofying libssh so that it integrates nicely with the current networking library. Progress so far is good, secure copy and SSH terminal are already supported (SFTP will be pushed back for the moment, NetConf over SSH has more priority currently).

Take a look at the following examples to get a first impression of the interface and the use of the library. The first example uploads a file via SCP and then reads it back:


using namespace Poco::SSH;

DummyValidator val; //auto-accepts all servers, for testing only
Poco::Net::SocketAddress addr(SERVER, 22);
Poco::AutoPtr<SSHSession> ptrSes = new SSHSession(val, addr, USER, PWD);
Poco::File locFile(“dummy.file”);
Poco::Path remFile(“/tmp/dummy.file”);
std::ifstream in(“dummy.file”, std::ios::binary);
poco_assert (in);

// now write the file
SCPOutputStream out(*ptrSes, locFile, remFile);
Poco::StreamCopier::copyStream(in, out);
out << std::flush;

// read it back
SCPInputStream in(*ptrSes, remFile);
Poco::StreamCopier::copyStream(in, std::cout);
The second example opens a shell at the server and executes a command:

DummyValidator val;
Poco::Net::SocketAddress addr(SERVER, 22);
Poco::AutoPtr ptrSes = new SSHSession(val, addr, USER, PWD);
SSHTerminal term(*ptrSes);
SSHChannel channel = term.openShell();
SSHChannelOutputStream out(channel);
SSHChannelInputStream in(channel);
out << "ls -al\n";
out << std::flush;
// simplified: read only one line
std::string txt;
std::getline(in, txt);