我想了解如何使用Ssh.NET判断连接是否成功建立:
SshClient client = new SshClient("127.0.0.1", 22, "root", "");
client.Connect();
// Connection ok? Then continue, else display error
SshCommand x = client.RunCommand("service apache2 status");
client.Disconnect();
client.Dispose();
我该如何逻辑上证明"client.RunCommand("service apache2 status");"的结果呢?
例如,如果(x == "apache2 is running")
IsConnected
返回 true,但调用ListDirectory
会导致错误(System.NotSupportedException: Request 'ping' is not supported.
)。这不能通过KeepAliveInterval
来解决。相反,我必须在每次使用后断开连接以强制 IsConnected 返回 false,并因此在每个请求上创建一个新连接。希望这个评论能帮助将来的某个人... - JohnLBevan