我在 ASP.NET Web 服务中有一个简单的类。它在我的本地系统上运行良好,甚至在我设置的开发环境上运行良好,但是每当我尝试在生产服务器上发送文件时,我都会收到以下错误:
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 不起作用有一个简单的原因吗?
如果这是一个安全问题,那么有什么办法可以解决吗?我需要立即让这个工作。