0 votes
by (120 points)
edited

I am trying to close or open one of the port on Cisco Router 2811. When using putty, here are the commands

After SSH login

config t int f0/0/0 no shutdown

I was able to login router using Rebex SSH lib. I then

    respString = ssh.RunCommand("config t\r\n");                
            textBox1.Text += respString;

Which returns correct response. The router is now in config mode. the command prompt looks like this now: router1(config)#

I then send respString = ssh.RunCommand("int f0/0/0\r\n"); Which cause the following exception:

Rebex.Net.SshException: Error while sending packet. ---> System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine
   at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at Rebex.Net.ProxySocket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at Rebex.Net.SshSession.clmbOg(BBdsJfZ , Boolean )
   --- End of inner exception stack trace ---
   at Rebex.Net.SshSession.clmbOg(BBdsJfZ , Boolean )
   at Rebex.Net.SshSession.clmbOg(BBdsJfZ )
   at Rebex.Net.SshSession.BGzjKi(SshChannelType , Int32 , Object[] )
   at Rebex.Net.SshSession.OpenSession()
   at Rebex.Net.Ssh.StartCommand(String command)
   at TestSSH.Form1.btnConnect_Click(Object sender, EventArgs e) in 

1 Answer

0 votes
by (73.5k points)
edited

To determine the cause of the exception we need a communication log. How it can be produced is described here. Can you send it to support@rebex.net please?

Some comments to your code:

1) the RunCommand method runs one separate command (in newly created ssh-subchannel) and exits. It means the command runs in new clear envirnoment, so it is unaffected by any changes made by previous calls of the RunCommand, StartCommand or StartShell methods. So using the RunCommand method in this case cannot work. You need to use the StartShell method.

2) there is no need to specify \r\n in the RunCommand method. Some servers may have problems with it

...