[尝试使用SSH.net连接到cisco无线控制器并为其添加一个mac地址。当我调试代码时,我在客户端的“ IsConnected”属性上得到“ true”,但是当我登录到控制器本身并执行“ Show loginsession”时,我没有看到假定的连接。
此外,当我到达var result = client.RunCommand(comman.ToString()).Result;
时,代码将挂起,根本没有任何响应。已经离开了几分钟,没有超时或返回任何错误。
public WebAPIEndPoint Put(WebAPIEndPoint console)
{
var connectionInfo = new ConnectionInfo(hostIP, 22, "UserName", new PasswordAuthenticationMethod("UserName", "Password"));
using (var client = new SshClient(connectionInfo))
{
client.Connect();
var command = client.CreateCommand("config macfilter add 00:17:ab:ea:d4:aa 5 0 Testing1234");
var result = client.RunCommand(comman.ToString()).Result;
Console.WriteLine(result);
client.Disconnect();
return console;
}
}
您的服务器似乎不支持SSH“ exec”通道。因此,您不能使用CreateCommand
/ RunCommand
。
您必须使用“外壳”通道(SshClient.CreateShell
或SshClient.CreateShell
)。通常不建议将其用于命令自动化。 SSH.NET甚至更是如此,它甚至不允许您关闭“ shell”通道的伪终端。这带来了很多讨厌的副作用,尤其是在Linux上使用“智能” shell时。但是对于像您这样的设备,它可能是可以忍受的,并且还是唯一的解决方案。
SshClient.CreateShellStream