下面是我找到的一段代码,我想请问的是,如果连接ftp服务器但还没登陆的时候会返回一段欢迎信息,当程序执行到 “WebResponse response = reqFTP.GetResponse()”时候,会出现“基础连接已经关闭: 接收时发生错误。”的错误提示(如果ftp服务器没有欢迎信息的话就不会出错),请问这个问题怎么解决private string[] GetFileList(string ftpServerIP, string ftpUserID,string strFtpPort, string ftpPassword)
{
string[] downloadFiles;
StringBuilder result = new StringBuilder();
FtpWebRequest reqFTP;
try
{
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP+":"+strFtpPort + "/"));
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
reqFTP.Method = WebRequestMethods.Ftp.ListDirectory; // reqFTP.Method = WebRequestMethods.Ftp.GetFileSize;//获取FTP服务器上的文件大小
WebResponse response = reqFTP.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string line = reader.ReadLine();
while (line != null && line != "")
{
// if (line.StartsWith(TelCode))//如果是StartsWith以TelCode开头的文件名
//{
//string s=Encoding.UTF8.
result.Append(line.ToLower());
result.Append("\n");
line = reader.ReadLine();
} result.Remove(result.ToString().LastIndexOf('\n'), 1);
reader.Close();
response.Close();
return result.ToString().Split('\n');
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
downloadFiles = null;
return downloadFiles;
}
}//GetFileList结束
{
string[] downloadFiles;
StringBuilder result = new StringBuilder();
FtpWebRequest reqFTP;
try
{
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP+":"+strFtpPort + "/"));
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
reqFTP.Method = WebRequestMethods.Ftp.ListDirectory; // reqFTP.Method = WebRequestMethods.Ftp.GetFileSize;//获取FTP服务器上的文件大小
WebResponse response = reqFTP.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string line = reader.ReadLine();
while (line != null && line != "")
{
// if (line.StartsWith(TelCode))//如果是StartsWith以TelCode开头的文件名
//{
//string s=Encoding.UTF8.
result.Append(line.ToLower());
result.Append("\n");
line = reader.ReadLine();
} result.Remove(result.ToString().LastIndexOf('\n'), 1);
reader.Close();
response.Close();
return result.ToString().Split('\n');
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
downloadFiles = null;
return downloadFiles;
}
}//GetFileList结束
你的程序有这样的问题吗??
还是你要出现这样的情况?
Connected to ftp3.scau.edu.cn.
220- 欢迎光临红满堂FTP服务系统!
220-
220-1、红满堂FTP所有内容仅为学习、交流、欣赏之用,请于下载24小时内删
220- 除,版权归其公司所有,切勿用于商业用途,否则由此引起一切后果自
220- 负。如果侵害到您的版权请立即写信通知我们,我们将在24小时之内删
220- 除。如果你确实喜欢并且需要,请购买正版。
220-2、红满堂FTP将竭力满足您的需要,但同时也不可能满足所有人的要求,
220- FTP也需要您的上载支持,谢谢!
220-3、上传时请按各FTP命名要求命名好,并按类别上传到相应的服务器的相
220- 应的目录,以便管理。谢谢合作。
220-4、凡上传有关反动、色情等内容一律封掉所在的整个IP段。
220-5、红满堂FTP是为大家服务的,禁止以FTP作私下交流中转用途,一经发现
220- 封掉所在的IP。
220-6、本FTP校内可匿名登陆,VIP用户请访问1021端口,校外用户请访问8021
220- 端口,校外帐号为scau:scau,每个ip一个线程。
220-7、欢迎使用华南农业大学FTP搜索引擎,网址为:
220- http://bingo.scau.edu.cn/search.html
220-8、对于红满堂FTP服务器有何意见或者建议请在东篱采菊BBS
220- (bbs.scau.edu.cn)上hmt版或hometown.scau.edu.cn/bbs/相应FTP区发
220- 贴或发Email至[email protected]。
220-
220-+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
220- FTP服务器分布说明:
220- ftp1.scau.edu.cn (软件/游戏/文档) IP:202.116.160.101
220- ftp2.scau.edu.cn (连续剧) IP:202.116.160.102
220- ftp3.scau.edu.cn (电影/音乐/综艺等) IP:202.116.160.103
220- ftp4.scau.edu.cn (卡通/集锦) IP:202.116.160.104
220-+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
220-
220- +++++++++++++++++++++++++++++++++++++++++++++++++++++
220- 警告:凡上传有关反动、色情等内容一律交予其所在学
220- 校及公安机关处理并封掉所在的整个IP段
220- +++++++++++++++++++++++++++++++++++++++++++++++++++++
220-
220-
220- 红满堂工作室
220- 2004/10/20220
User (ftp3.scau.edu.cn:(none)):