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();
}
// *
上面的代码抛出SshConnectionException
:“客户端未连接”,即使sftp.IsConnected
在 yield 之前检查true
。
文件按预期下载。
堆栈跟踪如下:
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