This project is read-only.

Sending multiple commands

Oct 28, 2010 at 4:33 PM

Hello,

I am trying the following code

 



 

string  st = ssh.Execute("cd tmp || echo {FAILED}");

st = ssh.Execute("pwd"

);

ssh.Disconnect();

the pwd is still showing the home directory. Is the connection made and break for each execute ?

Can you suggest , how can this kind of functionality be built

regards

 

 

 

Coordinator
Oct 28, 2010 at 6:21 PM

no, the connection remains the same until you disconnect it.

What happens is it opens the channel and closes it when the command its done.

Now, you can also execute multiple commands at the same time and it will use the same connection but will open different channel each time.

From what I could see there is a limit to up to 10 simulations open channels per connection (I mean channels of type session), so if you will try to execute more then 10 commands it will still work  but 11th command will wait for 1th one to finish.

 

Thanks,

Oleg

Dec 7, 2010 at 1:45 PM

It doesn't work this way when issuing commands to Cisco devices.

When connected to a Cisco device with this:
        var client = new SshClient("10.10.10.200", "user", "password");
        client.Connect();
        var cmd = client.RunCommand("dir");
        var result = cmd.Result;
        Console.WriteLine(result);
        Console.WriteLine((client.IsConnected) ? "IsConnected = true" : "IsConnected = false"); 

The output of 'dir' is printed to the screen immediately followed by "IsConnected = false"

However, when I connect to an OpenBSD box with this:
        var client = new SshClient("192.168.16.65", "user", "password");
        client.Connect();
        var cmd = client.RunCommand("ls -l");
        var result = cmd.Result;
        Console.WriteLine(result);
        Console.WriteLine((client.IsConnected) ? "IsConnected = true" : "IsConnected = false"); 

The output of 'ls -l' is printed to the screen immediately followed by "IsConnected = true".  Do you  have any Cisco gear you can try this on?  

 

 

Coordinator
Dec 7, 2010 at 8:57 PM

Hi,

 

Sorry, we dont have Cisco device here so I could test it on, if its possible to access to your machine you can send me more details to me privately and I will try to debug it.

So is it still prints out "dir" correclty but then disconnects?

Would it execute another command after this one?

 

Thanks,

Oleg

Coordinator
Dec 7, 2010 at 9:47 PM

I have a guess solution based on SharpSSH source code

can t you try to replace :

                    if (version.Equals("1.99"))
                    {
                        this.Write(Encoding.ASCII.GetBytes(string.Format("{0}", this.ClientVersion)));
                    }
                    else
                    {
                        this.Write(Encoding.ASCII.GetBytes(string.Format("{0}\n", this.ClientVersion)));
                    }

with 

this.Write(Encoding.ASCII.GetBytes(string.Format("{0}\n", this.ClientVersion)));

and let me know if it works.

 

Thanks,

Oleg

Dec 7, 2010 at 10:32 PM

I didn't see where to replace this in the code.  I have privately messaged you with creds to debug.

Sep 26, 2011 at 9:21 AM

did this ever get fixed?