1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| //Excetuer commandes
ConnectionInfo ConnNfo = new ConnectionInfo(host, 22, username,
new AuthenticationMethod[]{
// Pasword based Authentication
new PasswordAuthenticationMethod(username,password)
}
);
using (var ssh = new SshClient(ConnNfo))
{
ssh.Connect();
if (ssh.IsConnected)
{
string comm = "log print";
using (var cmd = ssh.CreateCommand(comm))
{
var returned = cmd.Execute();
var output = cmd.Result;
var err = cmd.Error;
var stat = cmd.ExitStatus;
var results = ssh.CreateCommand("plink.exe -ssh username@host -pw password").Execute();
Console.WriteLine(results);
}
}
ssh.Disconnect();
} |
Partager