1

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 SSH server until I tell it to disconnect?

Adam Haile
  • 30,705
  • 58
  • 191
  • 286

2 Answers2

2

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
kamranicus
  • 4,207
  • 2
  • 39
  • 57
1

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.

Chris Shouts
  • 5,377
  • 2
  • 29
  • 40
  • I mistyped, and that was just a example. The issue is still the same though... any example you want, the context does not persist. – Adam Haile Jun 29 '10 at 17:01