https://sshnet.codeplex.com/discussions/462442
这是我在讨论论坛上提出的一个老问题。不幸的是,这是一个问题,它又回来了,我又一次需要一个解决方案!
精华是:
将应用程序部署到Azure生产环境和UAT环境时,我遇到了以下问题。在本地运行此应用程序不会造成任何问题。该应用程序尝试连接到列表directorys或在短时间内将文件下载到流中。但是,在第一次尝试连接后,测试用例中会抛出此异常。但是,还应该注意的是,这并不总是会发生,因此客户端连接成功。
var connInfo = new PasswordConnectionInfo(this.host, this.port, this.username, this.password);
using (this.client = new SftpClient(connInfo))
{
client.ErrorOccurred += new EventHandler<Renci.SshNet.Common.ExceptionEventArgs>(client_ErrorOccurred);
this.client.Connect();
var response = new MemoryStream();
this.client.DownloadFile(this.intraDayFilePath, response);
this.client.Disconnect();
}
例外:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond xxx.xxx.xxx.xxx:22
at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
at Renci.SshNet.Session.SocketConnect(String host, Int32 port)
at Renci.SshNet.Session.Connect()
at Renci.SshNet.BaseClient.Connect()
at ---------
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()