Shell
objects started with Ssh.StartCommand
don't support running multiple commands. To do that, either call Ssh.StartCommand multiple times (if the commands are independent on each other) or call Ssh.StartShell
instead:
Rebex.Net.Ssh ssh = new Rebex.Net.Ssh();
ssh.Connect("domain.net");
Rebex.Net.SshPrivateKey key = new Rebex.Net.SshPrivateKey(@"private.ppk", "");
ssh.Login("username", key);
// start a shell
Shell sh = ssh.StartShell(ShellMode.WellKnownShell);
sh.SendCommand("pwd");
// read all response line-by-line
while (true)
{
// read a single response line
string line = sh.ReadLine();
// a value of null indicates end of response
if (line == null)
break;
// display the line
Console.WriteLine(line);
}
sh.SendCommand("cd /");
while (true)
{
// read a single response line
string line = sh.ReadLine();
// a value of null indicates end of response
if (line == null)
break;
// display the line
Console.WriteLine(line);
}