我想了解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“)的结果;”逻辑?
例如。 if(x ==“apache2正在运行”)
答案 0 :(得分:4)
您可以查看SshClient.IsConnected
属性:
if (!client.IsConnected)
{
// Display error
}
答案 1 :(得分:1)
您可以使用client.IsConnected用于此
using (var client = new SshClient("127.0.0.1", 22, "root", "")) {
client.Connect();
if (client.IsConnected) {
SshCommand x = client.RunCommand("cd ~");
} else {
Console.WriteLine("Not connected");
}
client.Disconnect();
}
答案 2 :(得分:0)
尝试使用IsConnected属性
BETWEEN