我需要连接到一个 ftp 并从中下载一个文件,但我无法连接到它。我已经指定了凭据并且能够通过我的浏览器进行连接,但不能通过 .NET。
FtpWebRequest downloadRequest = (FtpWebRequest)WebRequest.Create(ftpSite + "/" + TOC);
downloadRequest.Method = WebRequestMethods.Ftp.DownloadFile;
downloadRequest.Credentials = new NetworkCredential(userName, pass);
FtpWebResponse response = (FtpWebResponse)downloadRequest.GetResponse(); //execption thrown here
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
reader.ReadLine();
while (!reader.EndOfStream)
data.Add(reader.ReadLine());
reader.Close();
它会抛出WebException
407 错误,我不太清楚为什么。我的老板也很困惑。有什么见解吗?