sshExec.RunCommand("pwd", ref out, ref err);
sshExec.RunCommand("cd ..");
sshExec.RunCommand("pwd", ref out, ref err);
Each call to RunCommand()
will create a separate channel which runs independently of the others. In the common case (making an ssh connection to a unix server), each channel will invoke a separate shell instance. A command like cd
run in one channel won't affect subsequent commands launched in different channels.
To do what you want, you have to arrange to run the sequence of commands in the same RunCommand
invocation. Assuming the remote server is a unix server invoking a shell like bash
, you can use shell syntax, for example:
sshExec.RunCommand("pwd && cd .. && pwd", ref out, ref err);