cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Bookmark
|
Subscribe
|
1656
Views
0
Helpful
2
Replies

Trying to establish an ssh connection programmatically with a Cisco switch SG250, but the session keeps timing out

ktmachinex
Level 1
Level 1

Hi,

 

Not sure if it's the right place to ask, but I'm trying to establish an SSH connection programmatically and my session keep timing out.

 

I want to create a program to wrap the CLI commands of the Cisco switch (SG250-26) to make it easier to use for our users.

 

In the Cisco switch, I checked the SSH Service checkbox to enable the ssh service.

 

I am able to establish an ssh connection by using the command line "ssh [ip address]" but I can't wrap the CLI commands this way.

 

When I try to connect with an SSH client using the hostname, username and password (tried 3 differents library already), the ssh session keeps timing out.

 

Is there something I need to activate in the Cisco parameters to make this work out?

 

Any suggestion would be great.

 

Thanks,

Ktmachinex

2 Replies 2

balaji.bandi
Hall of Fame
Hall of Fame

Personally i do not belive these switches has any API programmability

 

what kind of test you using, post some example to understand, before we go further are you able to SSH in to device ?

BB

***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help

Requirements :

- Visual Studio 2019

- https://github.com/sshnet/SSH.NET

 

Steps :

  1. I connect to the cisco ip address 192.168.1.254 2. I go to the Security - TCP/UDP Services 3. I enable the SSH Service 4. I apply and save the change.
  2. In visual Studio, I try to execute this code :
                string host = "192.168.1.254";
                int port = 22;
                string username = "cisco";
                string password = "cisco";

                try
                {
                    using (var client = new SshClient(host, port, username, password))
                    {
                        // Throws an exception on the following line
                        client.Connect();

                        if (client.IsConnected)
                        {
                            //Do something
                        }
                    }
                }
                catch (Exception ex)
                {
                    //Session operation has timed out
                    Debug.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace.ToString());
                }

 

Each time I try to execute the Connect method, the session keep timing out.

 

When I try to use the same code to connect to a Linux server instead, it succeed.

 

Any suggestions?

 

I can send the "ssh [ip address]" command just fine, but I can't achieve my goal this way which is to wrap the cisco CLI commands into an "easier" to use program.