【发布时间】:2014-10-29 10:51:38
【问题描述】:
我有一个 MVC 应用程序并试图访问我在 IIS 中设置的本地 ftp 服务器 - 最终它将访问其他一些 ftp 服务器,但我只想在本地尝试一下。我使用 FtpWebRequest 编写了一个 c# 函数,但是当我调用 GetResponse() 时它返回错误:“远程服务器返回错误:(530) 未登录。”不确定如何以匿名或非匿名用户身份登录。如果我在 IIS 中有一个名为“MyFTPSite”的 FTP 站点并且启用了匿名身份验证,那么 URL 字符串的格式是否正确?网络凭证应该是什么? Files 目录是 ftproot 的子目录 - 我需要为 Files 文件夹添加虚拟目录吗?现在 ftp 站点的物理路径设置为 C:\inetpub\ftproot。 (在下面的代码中,localhost 故意拼写错误 b/c 该网站不希望我使用 localhost url)。
public override bool DownloadFile()
{
string fileName = System.IO.Path.GetFileName(this.UrlString);
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(this.UrlString);
request.Method = WebRequestMethods.Ftp.DownloadFile;
//anonymous logon
request.Credentials = new NetworkCredential("anonymous", "<my email>");
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
response.Close();
return true;
}
FTPDownload download = new FTPDownload(@"ftp://lclhost/MyFTPSite/Files/w4.pdf");
download.DownloadFile();
【问题讨论】:
标签: asp.net iis ftp ftpwebrequest