核心FTP连接已完成过期问题。 [英] Core FTP Connection Timmed out expired issue.

查看:134
本文介绍了核心FTP连接已完成过期问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我尝试使用c sharp代码连接到FTP时,我在下面提到的行上出现了过期错误。

response =(FtpWebResponse)请求。 GetResponse();

Hi,
When i try to connect to FTP using c sharp code i got time out expired error on below mentioned line.
response = (FtpWebResponse)request.GetResponse();

below is all my code which i use to connect to FTP using SSL.

{
            FtpWebResponse response = null;
            string str = info.DomainName.Trim().ToString() + ":" + info.Port;
            string username = info.Username;
            string password = info.Password;
            FtpWebRequest request = (FtpWebRequest)WebRequest.Create(new Uri("ftp://" + str + "/" + dirName));

            try
            {
                request.Method = WebRequestMethods.Ftp.ListDirectory;
                request.Credentials = new NetworkCredential(username, password);
                request.KeepAlive = info.KeepAlive;
                request.Timeout = info.TimeOut;//900000
                request.ReadWriteTimeout = info.TimeOut;
                request.UsePassive = (!info.UsePassive);
                request.Proxy = null;
                request.EnableSsl = true;

                RemoteCertificateValidationCallback orgCallback = ServicePointManager.ServerCertificateValidationCallback;
                try
                {
                    ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(OnValidateCertificate);
                    ServicePointManager.Expect100Continue = true;

                    response = (FtpWebResponse)request.GetResponse();
                    if (response.StatusCode.ToString() == "OpeningData")
                    {
                        response.Close();
                        return true;
                    }
                }
                finally
                {
                    ServicePointManager.ServerCertificateValidationCallback = orgCallback;
                }
               
            }
            catch (WebException ex)
            {
                if (request != null)
                {
                    request.Abort();
                }
                throw ex;
            }
            catch (Exception exx)
            {
                response.Close();
                throw exx;
            }
            return true;
        
}





请帮忙!提前谢谢。



Please help! thanks in advance.

推荐答案

您可能想尝试配置网络跟踪以查看发生了什么:



如何配置网络跟踪 [ ^ ]



如果删除sharedListeners部分,输出将直接进入输出窗口。您在App.Config文件中添加上述配置。



此外,WebException中有关于超时发生原因的更多信息,请尝试在catch中查看并查看调试器中的异常详细信息。
You may want to try to configure network tracing to see what is going on:

How to configure network tracing[^]

If you remove the sharedListeners section, the output will go directly to the output window. You add the above configuration in the App.Config file.

Also, there is more information in the WebException about why the timeout happened, try breaking inside the catch and view the exception details in the debugger.


这篇关于核心FTP连接已完成过期问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆