{"id":98,"date":"2007-07-27T12:30:35","date_gmt":"2007-07-27T10:30:35","guid":{"rendered":"http:\/\/appinf.com\/poco\/blog\/?p=98"},"modified":"2007-07-27T12:30:35","modified_gmt":"2007-07-27T10:30:35","slug":"pocossh","status":"publish","type":"post","link":"https:\/\/pocoproject.org\/blog\/?p=98","title":{"rendered":"PocoSSH"},"content":{"rendered":"<p>I&#8217;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).<\/p>\n<p>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:<\/p>\n<p><code><br \/>\nusing namespace Poco::SSH;<\/code><\/p>\n<p>DummyValidator val; \/\/auto-accepts all servers, for testing only<br \/>\nPoco::Net::SocketAddress addr(SERVER, 22);<br \/>\nPoco::AutoPtr&lt;SSHSession&gt; ptrSes = new SSHSession(val, addr, USER, PWD);<br \/>\nPoco::File locFile(&#8220;dummy.file&#8221;);<br \/>\nPoco::Path remFile(&#8220;\/tmp\/dummy.file&#8221;);<br \/>\nstd::ifstream in(&#8220;dummy.file&#8221;, std::ios::binary);<br \/>\npoco_assert (in);<\/sshsession><\/p>\n<p>\/\/ now write the file<br \/>\nSCPOutputStream out(*ptrSes, locFile, remFile);<br \/>\nPoco::StreamCopier::copyStream(in, out);<br \/>\nout &lt;&lt; std::flush;<\/p>\n<p>\/\/ read it back<br \/>\nSCPInputStream in(*ptrSes, remFile);<br \/>\nPoco::StreamCopier::copyStream(in, std::cout);<br \/>\nThe second example opens a shell at the server and executes a command:<br \/>\n<code><br \/>\nDummyValidator val;<br \/>\nPoco::Net::SocketAddress addr(SERVER, 22);<br \/>\nPoco::AutoPtr<sshsession> ptrSes = new SSHSession(val, addr, USER, PWD);<br \/>\nSSHTerminal term(*ptrSes);<br \/>\nSSHChannel channel = term.openShell();<br \/>\nSSHChannelOutputStream out(channel);<br \/>\nSSHChannelInputStream in(channel);<br \/>\nout &lt;&lt; \"ls -al\\n\";<br \/>\nout &lt;&lt; std::flush;<br \/>\n\/\/ simplified: read only one line<br \/>\nstd::string txt;<br \/>\nstd::getline(in, txt);<br \/>\n<\/sshsession><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;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 [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-98","post","type-post","status-publish","format-standard","hentry","category-news"],"_links":{"self":[{"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/98","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=98"}],"version-history":[{"count":0,"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/98\/revisions"}],"wp:attachment":[{"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=98"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=98"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=98"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}