【发布时间】:2016-10-12 06:58:42
【问题描述】:
我正在尝试使用 SSH.NET 通过 SSH 发送一个简单的命令。即使是最简单的测试代码也会失败。这是一个sn-p。
using (var ssh = new SshClient("ip", port, "username", "password"))
{
ssh.Connect();
while (true)
{
var result = ssh.RunCommand("AT").Execute();
Console.Out.WriteLine(result);
}
}
AT 命令应该回显 OK,但没有。相反,我收到了 SSH 目标发出的自定义超时消息。我在超时消息中看到与它使用的提示相对应的设备名称,从中我可以得出结论,登录有效(也使用各种 SSH 程序进行了测试),但命令本身没有执行。我尝试将\n 和\r\n 添加到命令中,但没有结果。我做错了什么?
编辑 1:
结果的输出是 \r\nCommand Line Interface\r\nDeviceName> Custom idle timeout 我认为 Visual Studio 会将行尾转换为 Windows 行尾。
编辑 2:
使用 Plink plink.exe username@ip -pw password "AT" > log.txt 会产生与 Visual Studio 相同的输出。 Plink 等待超时并终止,log.txtcontains \r\nCommand Line Interface\r\nDeviceName> Custom idle timeout。
使用 PuTTY 我看到了
Using username "username".
username@host's password:
Entering character mode
Escape character is '^]'.
Command Line Interface
DeviceName>
是在您开始输入命令之前编写的。可能是在主机准备好接收命令之前输入命令,导致命令挂起,直到有反应出现?
【问题讨论】: