摘要:SSH.NET
.net可以透過SSH.NET這個library建立ssh連線,參考網址: https://sshnet.codeplex.com/
記綠一下程式碼
string host = "xxx";
string username = "abc";
//這邊用private key驗證,這樣就不用將密碼寫入程式中
PrivateKeyFile pkf = new PrivateKeyFile("X:\\ssh_pk\\id_rsa");
using (SshClient client = new SshClient(host, username, pkf))
{
client.Connect();
SshCommand cmd = client.CreateCommand("who");
cmd.CommandTimeout = TimeSpan.FromSeconds(10);
string result = cmd.Execute();
Console.WriteLine(result);
client.Disconnect();
}
Console.ReadLine();
//用密碼驗證的寫法
//SshClient client = new SshClient(host, username, password))