C# FTP 550 error

前端 未结 6 792
抹茶落季
抹茶落季 2021-01-20 03:31

I\'m trying to programatically download a file in C# via FTP, here is the relevant code (obviously with fake credntials and URI):

try
{
    var request = Ftp         


        
相关标签:
6条回答
  • 2021-01-20 04:12

    Here is what I use, I bet the .Method is the main thing you are missing

            request = (FtpWebRequest)FtpWebRequest.Create(address);
            request.Credentials = new NetworkCredential("username", "password");
            request.UsePassive = true;
            request.UseBinary = true;
            request.Proxy = null;
    
            request.Method = WebRequestMethods.Ftp.DownloadFile;
            FtpWebResponse dataResponce = (FtpWebResponse)request.GetResponse();
    
    0 讨论(0)
  • 2021-01-20 04:16

    The Connection to my FTP-Server shows different behaviors, depending from where I try to connect. In my local Network it works with just one slash after the domain-part, e.g. ftp://test.test.com/folder/myfile.txt

    But on a remote machine I have to use two slashes like ftp://test.test.com//folder/myfile.txt

    The two-slashes-approach works in both cases.

    0 讨论(0)
  • 2021-01-20 04:18

    You have not set the Method.

     request.Method = WebRequestMethods.Ftp.DownloadFile;
    
    0 讨论(0)
  • 2021-01-20 04:28

    Turns out the FTP root isn't necessarily the same as the URL root. Perhaps I'm mixing up terminology, so let me explain: in my case, connecting to ftp.mydomain.com already starts at /folder, so my URL needed to just be ftp://ftp.mydomain.com/file.zip. IE8 knows how to eliminate the redundant /folder part in the original path while the FtpRequest class does not, which is why it worked in IE8 but not in the C# code.

    0 讨论(0)
  • 2021-01-20 04:35

    Put another slash at the beginning of the local path part (after hostname:port):

    var request = FtpWebRequest.Create("ftp://ftp.mydomain.com//folder/file.zip");
    

    This has worked for me.

    0 讨论(0)
  • 2021-01-20 04:36

    I recently had this problem and after much testing discovered that some module between here and there did not like a mixed case URI and so my resolution was to use .ToLower() on the URI

    0 讨论(0)
提交回复
热议问题