开发者

Error using FTPWebRequest on IIS7.5 and .NET 4.0

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜