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
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();
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.
You have not set the Method
.
request.Method = WebRequestMethods.Ftp.DownloadFile;
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.
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.
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