locked
whenever I start a ftp connection it stops RRS feed

  • Question

  • User1300300061 posted

    I am trying to read a file from  FTP location  

    The remote server returned an error: (425) Can't open data connection.

    private static void ReadIncomingFiles()
    {
    FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ConfigurationManager.AppSettings[XXXXXX]);
    request.Credentials = new NetworkCredential(ConfigurationManager.AppSettings[FTPUSERNAMEKEY], ConfigurationManager.AppSettings[YYYYYY]);
    request.Method = WebRequestMethods.Ftp.ListDirectory;
    FtpWebResponse response = (FtpWebResponse)request.GetResponse();   // error is coming here    The remote server returned an error: (425) Can't open data connection.

    Stream responseStream = response.GetResponseStream();
    List<string> files = new List<string>();
    StreamReader reader = new StreamReader(responseStream);
    while (!reader.EndOfStream)
    files.Add(reader.ReadLine());
    reader.Close();
    responseStream.Dispose();

    }

    Thursday, August 2, 2018 6:25 PM

All replies

  • User475983607 posted

    If there are not obvious configuration errors, then mostly likely a blocked port.  Make sure port 21 is not blocked as well as the inbound ports.  You might try switching active/passive mode.

    https://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.usepassive(v=vs.110).aspx

    Probably best to contact your system admin and ask for assistance.

    Thursday, August 2, 2018 6:51 PM
  • User-1053821806 posted

    I had an error like that and I had port 21 blocked ... I have no idea why it was like that. Thank you very much!

    Sunday, August 12, 2018 3:47 PM
  • User-1320437544 posted

    Hello,

    FTP server needs two open ports one for data transmission and another for data control. Let's say 21 data transmission and 22 data control (by standard its number is incremented by 1 on top of data transmission port number). The data control port is annonced by the server on connection request. Make sure it is accessible (forwarded). If forwarded properly. Than could be active/passive mode issue.

    ******************************************************

    Please don't forget to mark the answer if it helped.

    Tuesday, August 14, 2018 4:23 PM