Why ftpwebrequest fails to access ftp site

잠김 Why ftpwebrequest fails to access ftp site

  • 2012년 5월 11일 금요일 오후 11:09
     
      코드 있음

    Hi,

    I have ftp site with username and password, and I can access it in FileZilla. However, when accessing it in FtpWebRequest class in C#, it gives exception "The remote server returned an error: (550) File unavailable (e.g., file not found, no access)". The code is,

                    FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create("ftp://ftp.novusexpertus.com");
                    request.Method = WebRequestMethods.Ftp.ListDirectory;
                    request.Credentials = new NetworkCredential(username, password);

    What is the problem?

    Thanks


    York



    • 편집됨 york Z 2012년 6월 6일 수요일 오전 4:37
    •  

모든 응답

  • 2012년 5월 12일 토요일 오전 6:55
     
      코드 있음
    I think u r missing last slash(/) in URL
    "ftp://www.contoso.com/"
    Refer this link for detail
  • 2012년 5월 12일 토요일 오전 11:29
     
     

    Hi, 

    I would check

    Is files have permission to access?

    Is default ftp port number has been changed? if so you can specify "ftp://ftp.novustestlab.com:xx"

    Any firewall issue?

    also enable tracing to debug exact error. check from here 

    I hope this helps you...


    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".

  • 2012년 5월 12일 토요일 오후 4:09
     
     답변됨

    From the MSDN docs for FtpWebRequest:

    The URI may be relative or absolute. If the URI is of the form "ftp://contoso.com/%2fpath" (%2f is an escaped '/'), then the URI is absolute, and the current directory is /path. If, however, the URI is of the form "ftp://contoso.com/path", first the .NET Framework logs into the FTP server (using the user name and password set by the Credentials property), then the current directory is set to <userlogindirectory>/path.</userlogindirectory>

    So, adding the final '/' to the URI may do the trick, as it will tell the FtpWebRequest to start with the root directory of the site.


    • 편집됨 Greg Hurlman 2012년 5월 12일 토요일 오후 4:10
    • 답변으로 표시됨 york Z 2012년 5월 14일 월요일 오후 8:21
    •  
  • 2012년 5월 12일 토요일 오후 9:35
     
      코드 있음

    Actually in ftp.novusexpertus.com, I create a folder "flipbook" and a subfolder "Book" in it. I also create a ftp account with username and password using "flipbook" as root. But when using code below, I still get exception "The remote server returned an error: (550) File unavailable (e.g., file not found, no access)",

         FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create("ftp://ftp.novusexpertus.com/flipbook//Book");
                    request.Method = WebRequestMethods.Ftp.ListDirectory;
                    request.Credentials = new NetworkCredential(username, password);

    I can access ftp.novusexpertus.com/flipbook from FileZilla. It is a weird problem. Any thought?


    York


    • 편집됨 york Z 2012년 6월 6일 수요일 오전 4:38
    •  
  • 2012년 5월 12일 토요일 오후 11:34
     
     

    Hi Greg,

    Where is <userlogindirectory> defined?


    York

  • 2012년 5월 14일 월요일 오후 5:08
     
     

    Hi,

    Does it work from your code with ftp://ftp.novustestlab.com/flipbook/ (that is try the EXACT same thing in FileZilla and your own code, for now you tell us that it works with FileZilla but your code fails with *another* directory and you don't tell if it works with this particular one using FileZilla so this is a bit confusing) ?

    Also your code shows //Book rather than /Book. Not sure if this is a typo or really part of your code ? You could also try ftp://ftp.novustestlab.com/flipbook/Book/ (without // but with the final /).


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".



  • 2012년 5월 14일 월요일 오후 8:21
     
     답변됨 코드 있음

    This is solved. The reason is that since I set the ftp account at "flipbook" as root, it works as,

    FtpWebRequest.Create("ftp://ftp.novusexpertus.com/Book");


    York


    • 답변으로 표시됨 york Z 2012년 5월 14일 월요일 오후 8:21
    • 편집됨 york Z 2012년 6월 6일 수요일 오전 4:39
    •