我正在尝试使用 c# 从 ftp 服务器读取 CSV 文件,但问题是它不允许我读取并抛出此错误
远程服务器返回错误:(530) 未登录。
我花了很多时间研究这个问题,不幸的是我还没有找到解决方案。任何帮助将不胜感激。
这是代码:
StringBuilder result = new StringBuilder();
FtpWebRequest reqFTP;
try
{
String ftpserver = "ftp://domain.com/StatusChanges_20120922_043057.csv";
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpserver));
reqFTP.UsePassive = false;
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential("test@domain.com", "password");
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.Proxy = GlobalProxySelection.GetEmptyWebProxy();
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('\n') >= 0)
result.Remove(result.ToString().LastIndexOf('\n'), 1);
reader.Close();
response.Close();
return result.ToString();
}
catch (Exception ex)
{
}