Click here to Skip to main content
15,885,196 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have developer a web application in asp.net .I use ssh.net to establish a connection between my application and the Cisco devices. i use the below code:

to connect
C#
var ip = DropDownList2.SelectedItem.Text;
var user = txtuser.Text;
var passw = txtpass.Text;
var connInfo = new Renci.SshNet.PasswordConnectionInfo(ip, 22, user, passw);
var sshClient = new Renci.SshNet.SshClient(connInfo);
try
{
    sshClient.Connect();


to run command i use 2 way:

2.1.
C#
var cmd = sshClient.RunCommand("show user");
Label1.Text = cmd.Result;

its work fine withe router and switch but not working with firewall for that i try to use shellStream :
2.2.
C#
var ss = this.shellStream;
sshClient.Connect();
this.shellStream = sshClient.CreateShellStream("dumb", 80, 24, 800, 600, 1024);

Console.WriteLine(SendCommand("enable", ss));

Console.WriteLine(SendCommand(passw, ss));

Console.WriteLine(SendCommand("show looging", ss));

i can send multiple command to divice but my probbleme is how to display the result of this command from the shellStream. i try some thing like that but is not working
C#
string reslt = Console.ReadLine();
Label1.Text = Reslt;

i try to mixed this 2 way like this

C#
this.shellStream = sshClient.CreateShellStream("dumb", 80, 24, 800, 600, 1024);

Console.WriteLine(SendCommand("enable", ss));

Console.WriteLine(SendCommand(passw, ss));

Renci.SshNet.SshCommand cmd;

cmd = sshClient.RunCommand("show logging");

txtenablepass.Text = cmd.Result;


but is not working and i have this Exception

Additional information: Failed to open a channel after 10 attempts.

my question is how display the output in textbox from the shellStream ?
Posted
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900