Reputation: 6627
I'm integrating SharpSSH in on existing .NET 2.0 project. So can't switch to http://sshnet.codeplex.com/ or other newer library...
I have everything working for a single connection with a device and can run commands and upload files without problems.
But because this tool has to be able to update multiple devices at the same time the application starts multiple sharpssh connections at the same time. Then everything keeps on working but sometimes a file isn't uploaded completely and the error "session is down" is thrown.
SshTransferProtocolBase tx = new Scp(_hostname, _username, _password);
tx.Connect();
tx.OnTransferProgress += new FileTransferEvent(tx_OnTransferProgress);
tx.Put(sshSource.FullName, "/tmp/" + Path.GetFileName(sshTarget));
// --> tx.Put throws the error
When replacing "new Scp" with "new Sftp" like this
SshTransferProtocolBase tx = new Sftp(_hostname, _username, _password);
The error message is: "inputstream is closed" or "session is down"
Any ideas on how to avoid this?
Thanks a lot, Frank
Upvotes: 2
Views: 1793
Reputation: 1207
I had been struggling with the same problem. Getting "session is down" errors during multiprocessing is a known issue about SharpSSH. This library is no longer being updated. So I suggest you using another SSH librarry such as SSH.NET: https://github.com/sshnet/SSH.NET
It is easy to use. An example:
SshClient sshobject = new SshClient(OSShostIP, OSSusername, OSSpassword);
sshobject.Connect();
sshobject.RunCommand("mkdir /home/nedim");
sshobject.Disconnect();
Upvotes: 3
Reputation: 6627
solved by adding a retry loop with a definable maximum number of retries...
Upvotes: 0