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 = FtpWebRequest.Create("ftp://ftp.mydomain.com/folder/file.zip");
request.Credentials = new NetworkCredential("username", "password");
using (var response = request.GetResponse())
{
...
}
}
catch (WebException we)
{
...
}
The exception is thrown at request.GetResponse()
, and the error code is 550. The issue is not with the credentials or the URI, as they work just fine in IE and the file downloads successfully there. What am I missing? Is there some other kind of credential object I should be using? Is there a property on the request
object I'm not setting? Any help would be appreciated.