1

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 two specific commands doesn't work, and I can't seem to understand why.
The commands that fail are: changeto Production and terminal length 0.
My code is pretty simple (simplified for the question, but same flow):

using (var client = new SshClient(serverIP, port, username, password)
{
    client.Connect();
    var cmd = Client.RunCommand("terminal length 0");
    cmd = client.RunCommand("changeto Production");
    // Other command follow
}

While running the same commands 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.

4

1 回答 1

1

在 SSH.NET 库的 CodePlex 论坛上搜索和询问后,我明白了问题所在:该RunCommand()函数每次调用都会创建一个新的 shell。
新 shell 是使用默认环境创建的,并且由于terminal length 0更改changeto Production了以下命令的运行时环境,因此无法使用RunCommand().
我最终直接从 shell 流中写入和读取(使用SshClient.CreateShellStream())并使用Expect()来获取和解析我需要的输出。这样,所有命令都在同一个 shell 中执行。

于 2013-08-10T10:39:37.597 回答