Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FtpWebResponse, the operation timed out

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

like image 464
Paridokht Avatar asked Jul 16 '13 06:07

Paridokht


People also ask

Why is my FTP not working?

The FTP error “ECONNREFUSED” indicates a failed connection to the FTP server. If the error occurs, try one of these troubleshooting options: The most common quick fix for this FTP connection error is to change the port number from 21 (default FTP port) to 22 (default SFTP port), or the other way around.

How do I increase FTP session timeout?

In the Connections pane, click the server name, and then click the Sites node. In the Sites pane, click Set FTP Site Defaults... in the Actions pane. In the Advanced Settings dialog box, expand Connections, specify your time-outs in the Control Channel Timeout and Data Channel Timeout fields, and then click OK.

What does could not call endpoint due to read timed out?

Read Timed Out From the client side, the “read timed out” error happens if the server is taking longer to respond and send information. This could be due to a slow internet connection, or the host could be offline.


1 Answers

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;
like image 89
Paridokht Avatar answered Sep 18 '22 17:09

Paridokht