Specific command doesn't work

Jul 18, 2013 at 10:28 AM
Edited Jul 18, 2013 at 3:53 PM

I'm using SSH.NET to connect (with username + password) to a server and run some commands. Connection to server is made to manage some components via Cisco Application Control Software, but that shouldn't matter because command are sent as they are.

Connection to server works well, all other commands work too but one specific command doesn't work, and I can't seem to understand why.
The command that fails is: "changeto Production".
My code is pretty simple (simplified for the question, but same flow):
using (var client = new SshClient(serverIP, port, username, password)
    var cmd = Client.RunCommand("terminal length 0");
    cmd = client.RunCommand("changeto Production");
    // Other command follow
While running the same command via putty it works, and no, "changeto" shouldn't be "change to".
I think the problem here is changing scopes (changeto Production) via code, but can't understand why.

Any help will be appreciated.
Jul 18, 2013 at 1:00 PM
You forgot to mention what "doesn't work" means exactly.
Timeout? Error-Messages? Exceptions?
Jul 18, 2013 at 2:44 PM

No timeout, no exception, SshCommand.Result and SshCommand.Error are empty as well. It looks the same as if the command work, but it just doesn't do the action it suppose to do.

Jul 18, 2013 at 3:30 PM
Okay. then try the command "changeto Production" instead of "changeto Producation".
Hope it helps :P
Jul 18, 2013 at 3:32 PM

It's a typo here, not in code.

Jul 18, 2013 at 3:43 PM
come on... seriously? use copy&paste if you want people to debug your code!
So the code here isn't the code which doesn't work.. great!
Next time copy&paste, please!

What is "changeto Production" expected to do and how you know it does not work.

If it is changing the runtime-environment for following commands, keep in mind that
RunCommand() creates a new shell (with default environment) for every call.
Jul 18, 2013 at 4:06 PM
I'm sorry for the mistake, believe me it wasn't intentional and i'm not here to waste your or anyone else's time.
About the copy paste thing, it's not possible in my situation. I'm developing on an intranet completely isolated from the internet. So, copy paste here is not an option and that is why the code is simplified.

About the command, it should change the scope in which following commands will execute, when connecting to the server scope is "Test" and we need to change it to production to run it on the right "data"/devices.
Your last sentence probably explains why my problem rises, as indeed it should be the same shell because "changeto Production" affects the following commands.
Now "does not work" means command doesn't change the scope, but it's clear why because next command is executed in a new shell having Test scope again.
Is there a way to use the same shell for a series of commands? Or maybe send a series of commands?
I hope you understand where i'm heading to.

Thanks a lot for the quick answers and help, it's very appreciated.
Jul 18, 2013 at 4:35 PM
Can you combine commands in a cisco shell?
On Linux/Unix you can call commands in a row by adding "&&" or ";" between them.

Else you can check the sourcecode Renci.SshNet/SshCommand.cs or use SshClient.CreateShellStream()
and write your commands into the input-stream.
Jul 18, 2013 at 5:06 PM
About combining in cisco, will check that out with our network professionals as I can't find anything about it on google.
And thanks a lot, probably will do one of the things suggested (change SshCommand / use ShellStream).
Will update when a solution is found.
Aug 10, 2013 at 10:31 AM
I ended up writing and reading directly from the shell stream (using SshClient.CreateShellStream()) and playing with Expect() to get and parse the output I need.
Thanks a lot for the help :)