c# - SharpSsh Command Execution -
i trying create ssh client using c#. using tamir.sharpssh library. having issues sending command , getting appropriate response server.
the way have been testing sending on ls
command, followed cd..
command, followed ls
command again -- see whether or not cd..
command being executed properly. however, there no difference between first ls
command , second ls
command. not entirely sure doing wrong. perhaps using wrong ssh type. have provided code , output getting. have added output expect.
using tamir.sharpssh; namespace sshnetexample { class program { static void main(string[] args) { sshexec ssh = null; try { console.write("-connecting..."); ssh = new sshexec(host, username, password); ssh.connect(); console.writeline("ok ({0}/{1})", ssh.cipher, ssh.mac); console.writeline("server version={0}, client version={1}", ssh.serverversion, ssh.clientversion); console.writeline("-use 'exit' command disconnect."); console.writeline(); while(true) { string command = console.readline(); if(command == "exit") break; string data = ssh.runcommand(command); console.writeline(data); } } catch(exception e) { console.writeline(e.message); } if(ssh != null) { console.writeline("disconnecting..."); ssh.close(); console.writeline("ok"); } } } }
output:
expected output:
the sshexec class executing single command. logs server each command, , executes command asked to. it's similar (but not same) logging in, typing cd ..
, logging out again, logging in again , typing ls
- when logged in second time redirected home directory.
if want continue use sshexec, should combine commands can execute single command. in instance, example, execute ls ..
.
if want able issue multiple commands interactive session, @ sshshell
class instead of sshexec
.
Comments
Post a Comment