0

我在 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 不起作用有一个简单的原因吗?

如果这是一个安全问题,那么有什么办法可以解决吗?我需要立即让这个工作。

4

1 回答 1

0

这是一个安全问题,网站运行的用户没有建立 FTP 连接的权限。我是一名程序员而不是网站管理员,所以我不知道如何做到这一点。在搜索了微软在 IIS 上的 IIS 帮助后,终于通过了它。更改用户的解决方案在 SuperUser 上:

https://superuser.com/q/307168/68967

如果有人有更好的解决方案,请回复。如果有人认为这会引发安全问题,也请发布更多信息。

于 2011-07-06T17:38:56.220 回答