cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2760
Views
0
Helpful
2
Replies

Configure Cisco switch with C sharp application

Hi all, I'm trying to write the C sharp application to configure Cisco Switch.

I'm using Renci.SshNet library. The problem whe I'm trying to enter to CONFIG mode. The next command is being not recognized. Any idea?

Regard

Paweł

 

2 Replies 2

Dennis Mink
VIP Alumni
VIP Alumni
Can you share the code you have and a screenshot of the actual error. Thx
Please remember to rate useful posts, by clicking on the stars below.

Here's asynchronous version:

 

using (var sshclient = new SshClient(sutIP, sutUsername, sutPassword))
{
    sshclient.Connect();
    var cmd = sshclient.CreateCommand("configure terminal");
    var asynch = cmd.BeginExecute();
    while (!asynch.IsCompleted)
    {
        // Waiting for command to complete...
       System.Threading.Thread.Sleep(2000);
    }
    var result = cmd.EndExecute(asynch);

    sshclient.CreateCommand("interface Ethernet 1/1");
    asynch = cmd.BeginExecute();
    while (!asynch.IsCompleted)
    {
        // Waiting for command to complete...
       System.Threading.Thread.Sleep(2000);
    }
    result = cmd.EndExecute(asynch);

    sshclient.CreateCommand("speed 10000");
    asynch = cmd.BeginExecute();
    while (!asynch.IsCompleted)
    {
        // Waiting for command to complete...
        System.Threading.Thread.Sleep(2000);
    }
    result = cmd.EndExecute(asynch);

    sshclient.CreateCommand("end");
    asynch = cmd.BeginExecute();
    while (!asynch.IsCompleted)
    {
        // Waiting for command to complete...
        System.Threading.Thread.Sleep(2000);
    }
    result = cmd.EndExecute(asynch);

    sshclient.CreateCommand("show run");
    asynch = cmd.BeginExecute();
    while (!asynch.IsCompleted)
    {
        // Waiting for command to complete...
        System.Threading.Thread.Sleep(2000);
    }
    result = cmd.EndExecute(asynch);

    sshclient.Disconnect();
}

 

And here not:

 

List<string> commandSet = new List<string>();
commandSet.Add("configure terminal");
commandSet.Add("interface Ethernet 1/1");
commandSet.Add("speed 10000");
commandSet.Add("end");
commandSet.Add("copy running-config startup-config");
commandSet.Add("show running-config");

RunListOfSSHCommands(sutIP, sutUsername, sutPassword, commandSet);

public static void RunListOfSSHCommands(string sutIP, string sutUsername, string sutPassword, List<string> commandSet)
{

    using (SshClient ssh = new SshClient(sutIP, sutUsername, sutPassword))
    {
        ssh.Connect();
        foreach (string command in commandSet)
        {
             var result = ssh.RunCommand(command);
             Console.WriteLine(result.Result.ToString());
        }
        ssh.Disconnect();
    }
}

 

The error is attached.