FtpWebRequest returns error 550 File unavailable

前端 未结 15 2290
醉梦人生
醉梦人生 2020-11-30 09:41

I have created a small windows forms application to upload the file to one of our client\'s ftp site. But the problem that I\'m having is that when I run this application on

15条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 10:23

    I was also having the same issue. After monitoring the traffic with WireShark I understood the problem

    I had set up a new FTP site on my local IIS FTP server named 'testftp' The 'testftp' site was pointing to a folder named d:\ftp on my computer's hard disk I was getting the '550' error whenever i tried to execute the line in bold in C# code below ftpHostURL="ftp://127.0.0.1/testftp/test.htm"; request = (FtpWebRequest)WebRequest.Create(ftpHostURL); request.Proxy = new WebProxy(); //-----Proxy bypassing(The requested FTP command is not supported when using HTTP proxy)

                request.Method = WebRequestMethods.Ftp.UploadFile;
                request.Credentials = new NetworkCredential(ftpUserName, ftpPassword);
               // uploadFilePath = "d://test//tt.txt";
                using (var requestStream = request.GetRequestStream())
                {
                    using (var input = File.OpenRead(uploadFilePath))
                    {
                        input.CopyTo(requestStream);
                    }
                }
    

    I tried a lot of solutions mentioned in various websites but nothing helped. Then I came across a site that suggested to use WireShark to monitor the traffic.

    On monitoring the traffic using the RawCap Utility I saw that the application was trying to execute the code below

    STOR testftp/test.htm

    Then I understood the problem. IIS was expecting a folder named 'testftp' to be there under the ftp root folder which was not there. I was considering 'testftp' as the name of the virtual folder created in IIS where as IIS understood it as a folder under the FTP root

    Creating a folder named 'testftp' under the FTP root folder solved my issue.

    Hope this is helpful to someone

    Regards Mathew

提交回复
热议问题