C# Azure上运行的SFTP代码偶尔会出现服务器连接问题

C# Azure上运行的SFTP代码偶尔会出现服务器连接问题,c#,azure,sftp,ssh.net,C#,Azure,Sftp,Ssh.net,这是我在论坛上问的一个老问题。不幸的是,这个问题又回来了,我再一次需要解决它 其实质是: 在将我们的应用程序部署到Azure生产和UAT环境时,我遇到了以下问题。在本地运行此应用程序不会导致任何问题。应用程序多次尝试在短时间内连接到列表目录或将文件下载到流中。但是,在第一次尝试连接之后,在测试用例中会引发此异常。但是,还应该注意的是,这种情况并不总是发生,并且客户端成功连接的时间是soemtime var connInfo = new PasswordConnectionInfo(this.ho

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

其实质是:

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

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