gpt4 book ai didi

C# SSH.NET CreateCommand/RunCommand 不起作用

转载 作者:行者123 更新时间:2023-12-02 14:01:41 45 4
gpt4 key购买 nike

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





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 不应用于自动化。

关于C# SSH.NET CreateCommand/RunCommand 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45227308/

45 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com