本文介绍了核心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.
推荐答案
这篇关于核心FTP连接已完成过期问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!