C#SSH.NET模拟交互式shell

时间:2017-07-21 00:51:59

标签: c# .net ssh ssh.net

我想创建一个应用程序来向HP Switch和其他一些设备发送SSH命令。但是从HP Switch我得到响应"不支持SSH命令执行。"。

我使用代码的这一部分。

SshClient sshclient = new SshClient(IP,username, pass);
sshclient.Connect();
SshCommand sc = sshclient.CreateCommand("conf");
sc.Execute();
string answer = sc.Result;
label9.Text = answer;

有关如何进行交互式shell仿真的任何想法? 我发现只有这个问题的线程。 phpseclib - attempting to connect to an HP procurve switch returns error: SSH command execution is not supported

1 个答案:

答案 0 :(得分:0)

您的代码一般是正确的。但似乎特定设备不支持SSH“exec”频道,SshCommand类背后的内容。

正如answer to the question you have linked yourself建议的那样,你不得不使用SSH“shell”通道来模拟shell。

使用SshClient.CreateShell并将命令写入其输入流。

请注意,这只是针对您的具体情况的解决方法。通常,“shell”通道不得用于自动化。