本文介绍了远程服务器返回错误:227进入被动模式.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
简而言之,
我正在尝试从ftp读取5000个xml文件,但它抛出
远程服务器返回错误:227在读取第1500个xml文件时进入被动模式(89,202,213,212,6,32).我该怎么办才能帮助我.
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.
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;
}
}
推荐答案
这篇关于远程服务器返回错误:227进入被动模式.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!