Reputation: 1186
I am trying to create a SSH client using C#. I am using the Renci.SshNet library. I am having issues sending the command and getting an appropriate response from the server.
The way I have been testing it is by sending over the ls command, followed by cd.. command, followed by ls command again -- to see whether or not the cd.. command is being executed properly. However, there is no difference between the first ls command and the second ls command. I am not entirely sure what I am doing wrong. Perhaps I am using the wrong Ssh type. I have provided the code and the output I am getting. I have also added the output that I expect.
SshClient ssh = new SshClient("apk0rhel01", "dwaseem", "Da_011235813");
ssh.Connect();
while (true)
{
string command = Console.ReadLine();
if (command == "exit")
{
break;
}
var result = ssh.RunCommand(command);
if (result.Result.Length < 10)
continue;
Console.Write(result.Result);
}
ssh.Disconnect();
Output:
Expected Output:
Upvotes: 2
Views: 7075
Reputation: 30618
The answer to this is the same as the one for your question using the Tamir SSH library - you are using a class intended for executing single commands, which logs in and executes the command each time. You will not be able to use this like a shell.
If you want to implement interactive commands, you'll need something which keeps the connection open, and you'll need to deal with working out when a command has finished (which is normally done by looking for the prompt pattern). The Shell class provides methods for dealing with this - you can find examples of its use on their website.
Upvotes: 2