Click here to Skip to main content
16,011,475 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Briefly,
I'm trying to read 5000 xml files from ftp but it throws
The remote server returned an error: 227 Entering Passive Mode (89,202,213,212,6,32) on reading 1500th xml file. what shall i do somebody help me.


C#
    string[] files;
    files = GetFileList();
    foreach (string file in files)
     {
      xmlDoc.Load("ftp.Test.com/stats/" + file);
      XmlNodeList itemNodes = xmlDoc.SelectNodes("//Sport");
    }    
    // on reading 1600th xml file i get the Exception like The remote server returned an error: 227 Entering Passive Mode (89,202,213,212,6,32)

public string[] GetFileList()
    {
        string[] downloadFiles;
        StringBuilder result = new StringBuilder();
        WebResponse response = null;
        StreamReader reader = null;
        try
        {
            FtpWebRequest reqFTP;
            reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://ftp.Test.com/stats/"));
            reqFTP.UseBinary = true;
            reqFTP.Credentials = new NetworkCredential("Test", "Test");
            
            reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
            reqFTP.Proxy = null;
            reqFTP.KeepAlive = false;
            //reqFTP.EnableSsl = true;
            reqFTP.UsePassive = false;
            response = reqFTP.GetResponse();
            reader = new StreamReader(response.GetResponseStream());
            string line = reader.ReadLine();
            while (line != null)
            {
                result.Append(line);
                result.Append("\n");
                line = reader.ReadLine();
            }
            // to remove the trailing '\n'
            result.Remove(result.ToString().LastIndexOf('\n'), 1);
            return result.ToString().Split('\n');
        }
        catch (Exception ex)
        {
            if (reader != null)
            {
                reader.Close();
            }
            if (response != null)
            {
                response.Close();
            }
            downloadFiles = null;
            return downloadFiles;
        }
    }
Posted
Updated 17-Jul-12 0:26am
v2

1 solution

In high load situations the server might not have enough data ports defined to match the requests, or it might be venturing into a data port range that once again is not open on the firewalls.
 
Share this answer
 
Comments
deepgalley 17-Jul-12 7:03am    
please explain it clearly. need more detail
deepgalley 18-Jul-12 1:29am    
update your answer elaborately then ill accept this solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900