我使用以下代码从FTP网站获取档案。 它使用我的计算机,但在我用另一个电脑操作时,它只使用回音码(我可以看到,当我通过浏览器查阅FTP时,超文本是网页的代码)。 什么错误?
public String GetFilesAsString(string folder,string fileExtension)
{
StringBuilder result = new StringBuilder();
FtpWebRequest reqFTP;
try
{
String ftpserver = ftp + folder+"/";
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpserver));
reqFTP.UsePassive = false;
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(username, password);
reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8);
string line = "";
while (reader.Peek()>-1)
{
line = reader.ReadLine();
Console.WriteLine(line);//**********HTML was wrote out here*************
}
if (result.ToString().LastIndexOf(
) >= 0)
result.Remove(result.ToString().LastIndexOf(
), 1);
reader.Close();
response.Close();
return result.ToString();
}
catch (Exception ex)
{
}
return null;
}