7

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

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Paridokht
  • 1,374
  • 6
  • 20
  • 45
  • did you check the NetworkCredential username and password? because i guess you copied your code as is. – Mohammad abumazen Jul 16 '13 at 07:15
  • of course I've checked it!!..with the wrong user/pass it would get an authentication or login (not sure) error. – Paridokht Jul 16 '13 at 07:21
  • try to change the Uri to map to physical exist file like ""ftp://192.168.1.5:2100/C:/test.txt" and change request method to request.Method = WebRequestMethods.Ftp.DownloadFile; and see what you got. – Mohammad abumazen Jul 16 '13 at 07:41
  • I did this before..the same error!!! – Paridokht Jul 16 '13 at 07:45
  • try to change the port , set it to the default port 21 – Mohammad abumazen Jul 16 '13 at 07:53
  • no..the port is important..I think I figured it out...the usepasive property should be true not false!!! because when it is true the client should initiate a connection on the data port..but i cant answer my question until 7 hours later!!!..but I hope this work..thanks for your help :) – Paridokht Jul 16 '13 at 08:01

1 Answers1

15

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;
Paridokht
  • 1,374
  • 6
  • 20
  • 45