FtpWebResponse, the operation timed out

試著忘記壹切 提交于 2019-12-07 02:48:18

问题


I want to download files based on their date time from a ftp server..I can access this Ftp from CuteFtp third party and every thing is Okey..but when I run the code below at line GetRespone() I get this error: the operation has timed out. I download a sample file from this FTP programmatically with webclient requet and it was fine..but I need to use FtpWebRequest to get listDirectoryDetail and webClient does not support that..and one more thing, there is an exception in request: FtpWebRequest.ContentType threw an exception of type System.NotSupportedException.

here is my code:

Uri uri = new Uri("ftp://192.168.1.5:2100/");//the private address
        if (uri.Scheme != Uri.UriSchemeFtp)
        {
            return;
        }
        FtpWebRequest reqFTP;
        reqFTP = (FtpWebRequest)WebRequest.Create(uri);                             
        reqFTP.Credentials = new NetworkCredential("myuser", "mypass");
        reqFTP.KeepAlive = false;
        reqFTP.Method = WebRequestMethods.Ftp.ListDirectoryDetails;                               
        reqFTP.UseBinary = true;
        reqFTP.Proxy = null;
        reqFTP.UsePassive = false;
        FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();

PLEASE HELP :(


回答1:


I've Solved my Problem!...the UsePassive property should be set to True, when it is true the client should initiate a connection on the data port

reqFTP.UsePassive = true;


来源:https://stackoverflow.com/questions/17669990/ftpwebresponse-the-operation-timed-out

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!