Using Renci SSH.NET, I am trying to send a simple command to an ethernet switch over ssh, and then to read the response back from the switch. I can connect to the switch but it just hangs when I call Execute or RunCommand.
SshClient cSSH = new SshClient(ipValue, "admin", "admin");
cSSH.Connect();
SshCommand x = cSSH.RunCommand("show ip arp"); //this hangs
or
SshClient cSSH = new SshClient(ipValue, "admin", "admin");
cSSH.Connect();
var command = cSSH.CreateCommand("show ip arp");
command.Execute(); //this hangs
So then I tried using StreamReader and StreamWriter like this, and this works but hangs after the last response line and ReadLine() never returns null to end the read loop.
var s = cSSH.CreateShellStream("Commands", 240, 200, 132, 80, 1024);
var reader = new StreamReader(s);
var writer = new StreamWriter(s);
writer.AutoFlush = true;
//Send the command
writer.WriteLine("show ip arp");
writer.Flush();
Thread.Sleep(2000);
string l = "";
string szOut = "";
do
{
l = reader.ReadLine(); //Hangs on the last line and never returns null
szOut += l;
} while (l != null);
System.Windows.MessageBox.Show(szOut);
I've tried reader.StreamToEnd() but this also hangs. StreamReader does not support a timeout either.
I feel like I'm not understanding how this is meant to work but I've tried everything I can think of. Surely a synchronous command/response is possible with this library?