0

The program hangs at the .RunCommand(). Am I missing something really basic? It seems that this is the same code that works for other people and I know that the command is correct.

If I comment out the .runcommand() the program executes without error.

static void Main(string[] args)
    {
       PrivateKeyFile key = new PrivateKeyFile("private");
       using (var client = new SshClient("host", "user", key))
        {
            client.Connect();
            client.RunCommand("command");
            client.Disconnect();
        }
    }

I appreciate any help in advanced.

1 Answers1

0

It would be helpful to know what you're trying to connect to. Also, you may want to look into checking for errors in your code. You don't seem to have anything in place for validating that you've successfully connected... I would start there. Change the username and password to something that should fail and see if you see an error.

I've tried a number of different SSH libraries, for perl, python, .NET, you name it for automating changes to networking devices. The most common thing that I came across was that some connecting would work, logins worked fine, but attempting to pass a command would either time out or fail. I looked into using different versions of SSH but that didn't seem to make a difference. Some devices seem to require sending either "\n" or "\l\r" prior to accepting commands. I could get things to work using a linux box as a test server, but connecting to a switch or WAP would not allow me to pass commands.

In the end, I gave up and cobbled something together using AutoIT or tried using telnet - which is a bad idea in most environments, but perl, python, and .NET work wonderfully with telnet connections. PHP does as well.

I wasn't even able to pass commands in using SSH scripts (flat text files containing commands to be passed on successful login) that are supported by a number of applications ( putty, I think, and OpenSSH ).

Stuart Smith
  • 133
  • 5
  • I am trying to connect to a Cisco SX-10. Right now I have a janky set of batch files and VBscripts using plink that get the job done most of the time but it is unreliable. The library I am using has validation and I have confirmed that it is connecting successfully. I have tried the "/n" at the end of the command with no luck and will try the beginning of the command. – Grady Negronida Apr 23 '15 at 14:11
  • I was able to get openssh to work with cisco equipment using script files and I think also with putty but I was attempting to get Aerohive WAPS to work. They have a management application but I need to coordinate changes to the WAP config with changes to switch configuration... – Stuart Smith Apr 23 '15 at 14:23
  • Additionally the reason I am using open SSH to connect is because the username/pass wasnt authenticating correctly. I have also tried specifying to us port 23 to give telnet a try but no luck on that one. – Grady Negronida Apr 23 '15 at 14:31
  • If you want to use Telnet you can probably just use raw sockets... I think you can also use expect scripts with some telnet applications. Are you able to manually connect to the equipment using putty or the equivalent? – Stuart Smith May 01 '15 at 21:14
  • Yes i am able to manually connect using putty. It seems the SX-10 might not have a full SSH implementation or something. – Grady Negronida May 04 '15 at 19:22
  • Did Anyone ever resolve this? I am running into the same issue on the SX20. It always jams up at RunCommand. I can use putty with no problem. Can not get this to work programmatically with SSH.Net – Grayson Sep 28 '17 at 12:57
  • I'm guessing it's related to the SSH version the appliance is running. If you have a way to set it to ssh version 1 then try that and see if it's resolved. – Stuart Smith Sep 28 '17 at 13:29