SSH library times out when sending command..

0 votes
asked Dec 3, 2012 by walljm (520 points)
edited Jul 16, 2014
  Rebex.Net.Ssh ssh = new Ssh();
  ssh.Connect("192.168.1.10");
  ssh.CheckConnectionState();
  ssh.Timeout = 60 * 1000;

  ssh.Login("user", "password");
  string blah = ssh.RunCommand("show config"); // this works fine

  Shell shell = ssh.StartShell(ShellMode.Prompt);
  shell.Prompt = @">";
  shell.Encoding = System.Text.Encoding.UTF8;

  string r = string.Empty;
  shell.SendCommand("set cli screen-length 0"); // times out here.
  string prompt = shell.ReadAll();
  shell.Prompt = prompt.Substring(prompt.LastIndexOf("\n") + 1) + ">";

the above code throws a TerminalException: Response reading timed out. this code works on cisco devices.

help?

commented Dec 3, 2012 by walljm (520 points)
edited Dec 3, 2012

the server Rebex reports is running on the Juniper switch is: "SSH-2.0-OpenSSH_4.4" cisco uses: "SSH-1.99-Cisco-1.25"

2 Answers

+1 vote
answered Dec 4, 2012 by Lukas Matyska (59,450 points)
edited Dec 4, 2012
 
Best answer

This seems to be a limit of the Shell class. Can you please try to use our experimental VirtualShell class? It is more flexible. You can use it like this:

Rebex.Net.Ssh ssh = new Ssh();
...
VirtualTerminal vt = ssh.StartVirtualTerminal();
VirtualShell shell = new VirtualShell(vt);

shell.Prompt = Regex.Escape(@">");
shell.Terminal.Options.Encoding = System.Text.Encoding.UTF8;

string r = string.Empty;
shell.SendCommand("set cli screen-length 0");
string prompt = shell.ReadAll();
shell.Prompt = Regex.Escape(prompt.Substring(prompt.LastIndexOf("\n") + 1) + ">");
0 votes
answered Jul 16, 2014 by Pavel Matyska (13,980 points)
edited Jul 16, 2014

Hi, we have just release new Scripting API in 2014-R2 release. You can read more of its features on Scripting features page.

...