在 IIS7.5 和 .NET 4.0 上使用 FTPWebRequest 时出错

发布于 2024-11-17 23:22:54 字数 1288 浏览 3 评论 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 无法工作是否有一个简单的原因?

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

I have a simple class in an ASP.NET webservice. It runs fine on my local system and even on the development environment I've set up, but Anytime I try to send a file on the production server I get the following error:

Exception Error: The underlying provider failed on Open.

Here is the code that is being called:

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;
        }
    }

How can I troubleshoot this issue. The Server is IIS 7.5 running on Windows 2008 Server. I'm using .NET 4.0. Is there a simple reason why the FtpWebResponse would not be working?

If it's a security issue, then is there any way around it? I need to get this working immediately.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白芷 2024-11-24 23:22:54

这是一个安全问题,运行该网站的用户没有建立 FTP 连接的权限。我是一名程序员,而不是网站管理员,所以我不知道如何完成此任务。在搜索了微软关于IIS的IIS帮助之后,终于找到了答案。更改用户的解决方案位于 SuperUser:

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

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

It was a security issue, the user that the website was running as did not have permission to establish the FTP connection. I am a programmer and not a web site administrator, so I did not have a clue how to accomplish this. After searching through Microsoft's IIS help on IIS, finally worked my way through it. The solution to change the user is on SuperUser:

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

If anyone has any better solutions, please respond. If anyone feels this would open up security issues, also, please post more information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文