我在ASP.NET have服务中有一个简单的类。它在我的本地系统上运行得很好,甚至在我设置的开发环境中也运行得很好,但每当我尝试在生产服务器上发送文件时,我都会收到以下错误:
Exception Error: The underlying provider failed on Open.下面是被调用的代码:
public class FTPHelper
{
public static string SendFile(string ftpuri, string username, string password, string ftppath, string filename, byte[] datatosend)
{
if (ftppath.Substring(ftppath.Length - 1) != "/")
{
ftppath += "/";
}
FtpWebRequest ftp = (FtpWebRequest) FtpWebRequest.Create( ftpuri + ftppath + filename);
ftp.Method = WebRequestMethods.Ftp.UploadFile;
ftp.Credentials = new NetworkCredential(username, password);
ftp.UsePassive = true;
ftp.ContentLength = datatosend.Length;
Stream requestStream = ftp.GetRequestStream();
requestStream.Write(datatosend, 0, datatosend.Length);
requestStream.Close();
FtpWebResponse ftpresponse = (FtpWebResponse)ftp.GetResponse();
return ftpresponse.StatusDescription;
}
}如何解决此问题。服务器是在Windows 2008 Server上运行的IIS 7.5。我使用的是.NET 4.0。FtpWebResponse不工作有什么简单的原因吗?
如果这是一个安全问题,那么有什么方法可以绕过它吗?我得马上把它修好。
发布于 2011-07-07 01:38:56
这是一个安全问题,网站正在运行的用户没有建立FTP连接的权限。我是一个程序员,而不是一个网站管理员,所以我不知道如何做到这一点。在搜索了Microsoft在IIS上的IIS帮助后,我终于找到了它的方法。更改用户的解决方案是在SuperUser上:
https://superuser.com/q/307168/68967
如果有人有更好的解决方案,请回复。如果任何人觉得这会打开安全问题,也请张贴更多的信息。
https://stackoverflow.com/questions/6530419
复制相似问题