SharpSSH with Persistent ShellExec connections
I'm using SharpSSH to connect to an SSH server and I've tried using both SshShell and SshExec. I need to be able to take a series of commands and send them to the server in order, so SshShell doesn't really do what I need since I would have to wrangle streams the whole time and it seems that it would be a bit of a kludge. So I've tried SshExec but found one problem with it, every time I send a command it seems to be making a new connection and losing the context of the last command. For example if I ran the following commands:
pwd
cd .ssh
pwd
I would expect it to output
/home/adam
/home/adam/.ssh
But, instead it just ouputs "/home/adam" both times, meaning that the directory change was lost in between.
Is there a way I can configure this so that it maintains a constant connection to the SS开发者_如何学CH server until I tell it to disconnect?
Do this:
exec.RunCommand("pwd; cd Desktop; pwd")
I am not sure how to do advanced commands, but I tried that and it outputs:
/Users/MyUser
/Users/MyUser/Desktop
To cd to a hidden directory (any directory beginning with a dot (.) character), you need to enclose the value in quotes.
According to the documentation:
4) If the first component of the directory operand is dot or dot-dot, proceed to step 6.
6) Set curpath to the string formed by the concatenation of the value of PWD , a slash character, and the operand.
In short, cd '.ssh'
should do the trick.
精彩评论