Reputation: 4305
I am trying to download a file over FTP which is setup with implicit SSL. Here is my code so far:
open System.Net
let user = "user_name"
let pwd = "password"
let ftpLocation = @"ftp://*server ip*/*file location*"
let request = FtpWebRequest.Create(ftpLocation) :?> FtpWebRequest
request.Credentials <- new NetworkCredential(user, pwd)
request.Method <- WebRequestMethods.Ftp.DownloadFile
request.Proxy <- null
let response = request.GetResponse() :?> FtpWebResponse
I am getting a remote server error:
System.Net.WebException occurred
Message: Exception thrown: 'System.Net.WebException' in System.dll
Additional information: The remote server returned an error: (530) Not logged in.
What am I missing here? I thought I passed in the credentials the way they needed to be. I am having a difficult time finding any documentation on this.
Upvotes: 1
Views: 340
Reputation: 4305
I am leaving this here for the next poor person who has to do this. It took a lot of pieces from various places to get it to work:
let ftpLocation = @"ftp://*server ip*/path/to/file/example.txt"
let request = FtpWebRequest.Create(ftpLocation) :?> FtpWebRequest
let user = "username"
let pwd = @"password"
request.Credentials <- new NetworkCredential(user.Normalize(), pwd.Normalize())
request.EnableSsl <- true
ServicePointManager.ServerCertificateValidationCallback <- (fun sender certificate chain sslPolicyErrors -> true)
request.Method <- WebRequestMethods.Ftp.DownloadFile
request.Proxy <- null
let response = request.GetResponse()
let responseStream = response.GetResponseStream()
let reader = new StreamReader(responseStream)
Console.WriteLine(reader.ReadToEnd())
Console.WriteLine("Download complete")
reader.Close()
response.Close()
Upvotes: 3