2016-02-24 26 views
2

我嘗試從FTP下載.bak文件並將其保存到本地目錄中。遠程服務器上的錯誤:227進入被動模式(xxx,xxx,xxx,xx)

這是我的代碼:

Try 
     My.Computer.Network.DownloadFile("ftp://nameOfServer/file.bak", "C:\Users\Admin\Documents\BackUp\file.bak", "user", "password") 

    Catch ex As Exception 
     MessageBox.Show(ex.Message, "Error") 
    End Try 

當我執行的代碼我得到這個錯誤:

Error on the remote server: 227 Entering Passive Mode(xxx,xx,xxx,xxx,xxx,xx) 

我知道我需要將其更改爲主動模式,但我不能找到一種方法與我的代碼正常工作。 我該如何解決這個問題?謝謝

回答

1

您應該確保您正在通過遵循這個較舊的編輯正確下載文件。

After some fiddling around to recreate the issue, the issue was solved using the following code

Dim username As String = "username" 
Dim password As String = "password" 
Dim address As String = "address" 
Dim file As String = "file" 
Dim outputFile As String = "outputFile" 
My.Computer.Network.DownloadFile("ftp://" + username + ":" + password + "@" + address + "/" + file, outputFile) 

Or the following was more concisely able to solve the issue

My.Computer.Network.DownloadFile("ftp://username:[email protected]/file", "outputLocation") 

但對於你的問題,另一個可能的原因可能是由輸出目錄是缺少的,或者更可能的寫保護(通過安全策略或文件夾設置)被簡單地造成的。

最後,如果你有一切正確的代碼和文件結構明智的,我會建議聯繫FTP提供商,並確保FTP服務器配置和優化適當的使用。如果您無法聯繫您的ftp服務提供商尋求幫助,但是您可以訪問您的ftp設置,我建議您爲您的ftp服務器禁用被動模式,風險自擔。

+0

謝謝你的回答,但你的代碼給我同樣的錯誤信息。 –

+0

@ Esraa_92有點晚了,但我更新了答案,因爲答案在語法和邏輯上都不正確。我還在編輯中提到,如果所有的問題都失敗了,您應該聯繫您的ftp提供商以獲取有關此問題的幫助。 – Speentie8081

相關問題