I'm having a strange issue with Renci SSH.Net:
var sftp = new SftpClient(remoteHost, remotePort, remoteUserName, remotePassword);
try
{
sftp.Connect();
using (var file = new FileOutputStream(filePath))
{
sftp.DownloadFile(remoteFileName, file);
}
sftp.Disconnect(); // *
}
catch (Exception ex)
{
// log stuff
throw;
}
finally
{
sftp.Dispose();
}
The above code throws at // *
with the SshConnectionException
: "Client not connected", even though on inspecting sftp.IsConnected
just before yields true
.
The file downloads as expected.
The stacktrace is as follows:
at Renci.SshNet.Session.SendMessage(Message message)
at Renci.SshNet.Session.SendDisconnect(DisconnectReason reasonCode, String message)
at Renci.SshNet.Session.Disconnect()
at Renci.SshNet.BaseClient.Disconnect()
at My.Program.MyMethod() in c:\path\to\my\program.cs:line 42