I am trying to make a program that connects to an SSH server and then logs me in. I have successfully created tracert or ping commands, but SSH connection doesn't work for me at all. I am using SSH.NET. I get no output to my text box. I already followed some advice from StackOverflow (Execute long time command in SSH.NET and display the results continuously in TextBox), but it did not work for me.
Here's the code:
private void button5_Click(object sender, EventArgs e)
{
string host = "someserverip";
string username = textBox6.Text;
string password = textBox8.Text;
string ipaddress = textBox12.Text;
using (var radius = new SshClient(host, port, username, password))
{
radius.Connect();
var cmd = radius.CreateCommand("check-host" + ipaddress);
var result = cmd.BeginExecute();
using (var reader = new StreamReader(
cmd.OutputStream, Encoding.UTF8, true, 1024, true))
{
while (!result.IsCompleted || !reader.EndOfStream)
{
string line = reader.ReadLine();
if (line != null)
{
textBox10.Invoke(
(Action)(() =>
textBox10.AppendText(line + Environment.NewLine)));
}
}
}
cmd.EndExecute(result);
}
textBox10.ScrollBars = ScrollBars.Vertical;
}