Witam.
Mam problem z odbiorem strumienia powrotnego po wysłaniu komend po SSH. Biblioteka z której korzystam to SSH.NET . Mógłby ktoś podać przykład jak odebrać taki strumień powrotny w tym przypadku? Serdecznie pozdrawiam.
private void connect_btn_Click(object sender, EventArgs e)
{
int port = 0;
Int32.TryParse(ssh_box.Text, out port);
ConnectionInfo sshc = new ConnectionInfo(ip_box.Text,port, user_box.Text,
new AuthenticationMethod[] {new PasswordAuthenticationMethod(user_box.Text,pass_box.Text)});
var ssh_client = new SshClient(sshc);
try
{
var task = new Task(async() => {
ssh_client.Connect();
if (ssh_client.IsConnected)
{
listView1.Invoke(new Action(delegate ()
{
listView1.Items.Add("Connected!");
}));
}
await Task.Delay(5000);
ssh_client.RunCommand("touch /var/etc/persistent/ct");
listView1.Invoke(new Action(delegate ()
{
listView1.Items.Add("Sent touch /etc/persistent/ct");
}));
await Task.Delay(5000);
ssh_client.RunCommand("save");
listView1.Invoke(new Action(delegate ()
{
listView1.Items.Add("Sent save");
}));
//await Task.Delay(5000);
//ssh_client.RunCommand("reboot");
//listView1.Invoke(new Action(delegate ()
//{
// listView1.Items.Add("Sent reboot");
//}));
ssh_client.Disconnect();
listView1.Invoke(new Action(delegate ()
{
listView1.Items.Add("Disconnected!");
}));
});
task.Start();
}
catch (Renci.SshNet.Common.SshAuthenticationException)
{
listView1.Items.Add("Wrong pass or user");
ssh_client.Disconnect();
}
catch (System.Net.Sockets.SocketException)
{
listView1.Items.Add("Wrong port or host");
ssh_client.Disconnect();
}
}