Answer the question
In order to leave comments, you need to log in
C# SSH keys error when running in multiple threads, what to do?
Hello everyone, I am writing a WinForm app on Sharp, its essence is to make several connections to different ssh. In one thread, the check works fine, but as soon as the second thread starts and more errors begin, as I understand the public keys. I've been looking for solutions for more than a day, but I still don't understand how it works.
Additionally, to work with ssh, I attached the Tamir.SharpSsh extension.
Here is an example of a function that runs in separate threads
private void Potok(Object x)
{
string[] tdata = explode(";", (string)x);
string h = tdata[0];
string l = tdata[1];
string p = tdata[2];
ssh = new SshShell(h, l, p);
try
{
ssh.Connect();
if (ssh.Connected == true)
{
lock (valueLocker)
{
string goodresult = h + ";" + l + ";" + p + "\r\n";
if (File.Exists(outpf))
{
File.AppendAllText(outpf, goodresult);
}
else
{
File.Create(outpf);
File.AppendAllText(outpf, goodresult);
}
}
}
}
catch (Tamir.SharpSsh.jsch.JSchException ex)
{
throw ex;
ssh.Close();
}
catch (System.ArgumentException e)
{
throw e;
ssh.Close();
}
catch (System.Exception exts)
{
throw exts;
ssh.Close();
}
pcnt--;
ssh.Close();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question