F#通过FTP使用隐式SSL下载文本文件

时间:2016-03-05 05:42:46

标签: ssl ftp f# ftps

我正在尝试通过FTP下载一个使用隐式SSL设置的文件。到目前为止,这是我的代码:

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

我收到远程服务器错误:

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.

我在这里缺少什么?我以为我按照他们需要的方式传递证书。思考?我很难找到关于此的任何文档。任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:3)

我要离开这里,为下一个必须这样做的穷人。它需要从不同的地方获得很多作品才能让它发挥作用:

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()