This project is read-only.

No result

Jan 26, 2012 at 7:24 AM
Edited Jan 26, 2012 at 8:11 AM

I cant get the result after executing the command. What may the the cause? Am I missing smt...

                using (var client = new SshClient(NodeIpAddress, UserName, Password))                {

                    client.Connect();
                    var cmd = client.RunCommand("show version");
                    string tOutput = String.Empty;
                    tOutput = cmd.Result;
                    client.Disconnect();
                }

client is connected but cmd. result and cmd.Error are both empty. cmd.ExitStatus = 1

connected client is Cisco Systems ASR5000

 

Even I tried this but nothing changed:

                using (var client = new SshClient(NodeIpAddress, UserName, Password))
                {
                    client.Connect();

                    var input = new System.IO.MemoryStream(System.Text.Encoding.ASCII.GetBytes("1\r\n")); // or 2 

                    //var input = new MemoryStream();
                    //var sr = new StreamWriter(input);
                    var output = Console.OpenStandardOutput();

                    var shell = client.CreateShell(input, output, output, "xterm", 80, 24, 800, 600, "");
                    shell.Stopped += delegate(object sender, EventArgs e)
                    {
                        Console.WriteLine("\nDisconnected...");
                    };
                    shell.Start(); // this will send your input to the shell
                    shell.Stop(); // This will stop the shell

                    //var cmd = client.RunCommand("ls -l");  // This command should run now

                    if (client.IsConnected)
                    {
                        string strCmd = "show version";
                        var cmd = client.RunCommand(strCmd);
                        string tOutput = String.Empty;
                        tOutput = cmd.Result;
                        client.Disconnect();
                    }

                }

Coordinator
Jan 27, 2012 at 4:42 PM

Hi,

 

Sorry,

But it seems that you doing everything correct.

Does it works if you trying to connect to different server?

 

Thanks,

Oleg