1

https://sshnet.codeplex.com/discussions/462442

这是我在论坛上问的一个老问题。不幸的是,这个问题又回来了,我再次需要一个解决方案!

本质是:

在将我们的应用程序部署到我们的 Azure 生产和 UAT 环境时,我遇到了以下问题。在本地运行此应用程序不会导致任何问题。该应用程序会在很短的时间内多次尝试连接到列表目录或将文件下载到流中。但是,在第一次尝试连接后,会在测试用例中引发此异常。然而,还应注意,这并不总是发生,有时客户端会成功连接。

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()
4

0 回答 0