2016-03-05 160 views
1

我試圖通過使用隱式SSL設置的FTP下載文件。這是我到目前爲止的代碼:F#通過隱式SSL通過FTP下載文本文件

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. 

缺少什麼我在這裏?我認爲我以他們需要的方式通過了證書。思考?我有一個非常困難的時間找到任何文件。任何幫助表示讚賞。

+0

我發現[這個職位上的SO(http://stackoverflow.com/questions/10352165/using-ftpwebrequest-with-an- error-the-remote-server-returned-error-530-not-loge),它指向[關於這個場景的文章](http://www.godwinpaul.com/2013/06/25/ftp-c-誤差最遠程服務器返回-AN-錯誤-530-未登錄/)。它有幫助嗎? – Roujo

+0

@Roujo,也許但我不知道它爲域變量需要什麼,我找不到域變量的示例。這應該是什麼?這應該是FTP地址? –

+0

@Roujo,謝謝。這是我需要這個工作的一部分。 –

回答

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

感謝隊友,看起來不錯! –