I have triying to send ssh commands to my CPU using Renci and sshnet libraries by clicking two buttons. First button, it works fine but when i clicked the second, it says
'System.ObjectDisposedException'
for client At those rows.
client.Connect();
shCommand cmd3 = client.RunCommand("ls -la checkEth*");
Could anyone help?
public partial class Form1 : Form
{
SshClient client = new SshClient("192.168.1.5", "deneme", "deneme");
int milliseconds;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Console.WriteLine("Button 1 clicked");
using (client)
{
milliseconds = 200;
Thread.Sleep(milliseconds);
client.Connect();
SshCommand cmd = client.RunCommand("ls > checkEth.txt");
System.Diagnostics.Debug.WriteLine("chechethYapildi 1: " + cmd.Result);
Thread.Sleep(milliseconds);
SshCommand cmd2 = client.RunCommand("ls -la checkEth*");
System.Diagnostics.Debug.WriteLine("com 1:" + cmd2.Result);
textBox1.Text = (cmd2.Result);
System.Diagnostics.Debug.WriteLine("cevapgelecek");
//client.Dispose();
}
client.Dispose();
}
private void button2_Click(object sender, EventArgs e)
{
using (client)
{
client.Connect();
SshCommand cmd3 = client.RunCommand("ls -la checkEth*");
textBox1.Text = (cmd3.Result);
System.Diagnostics.Debug.WriteLine("ikinci butona basıldı");
}
}
}