这个问题在这里已经有了答案:





SSH.NET is not executing command on device

(1 个回答)


去年关闭。




我想创建一个应用程序来将 SSH 命令发送到 HP 交换机和其他一些设备。但从 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

请您参考如下方法:

您的代码通常是正确的。但似乎特定设备不支持 SSH“exec” channel ,SshCommand 背后的原因是什么?类(class)。
作为answer to the question you have linked yourself建议,不幸的是,您必须使用 SSH“shell” channel 来模拟 shell。
为此使用 SshClient.CreateShell并将命令写入其输入流。
请注意,这只是针对您的特定情况的解决方法。一般来说,“shell” channel 不应用于自动化。


评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!