2015-11-23 36 views
2

我試圖將文件上傳到FileZilla FTP服務器。我已經在我的電腦中安裝了服務器,並且正在使用簡單的C#腳本來上傳文件。當我從同一臺機器運行腳本時,它可以正常工作。當我試圖從相同或不同的局域網從另一臺計算機上運行腳本我這有問題:當使用WebClient.UploadFileAsync時,某些機器上的文件未上傳到FTP服務器

(not logged in) (ClientIP)> USER userID 
(not logged in) (ClientIP)> 331 Password required for userID 
(not logged in) (ClientIP)> PASS *************** 
    userID (ClientIP)> 230 Logged on 
    userID (ClientIP)> OPTS utf8 on 
    userID (ClientIP)> 202 UTF8 mode is always enabled. No need to send this command. 
    userID (ClientIP)> PWD 
    userID (ClientIP)> 257 "/" is current directory. 
    userID (ClientIP)> TYPE I 
    userID (ClientIP)> 200 Type set to I 
    userID (ClientIP)> PASV 
    userID (ClientIP)> 227 Entering Passive Mode (ClientIP) 

什麼可能造成的問題嗎?我從我自己的電腦接收的消息如下:

(not logged in) (pcIP)> USER userID 
(not logged in) (pcIP)> 331 Password required for userID 
(not logged in) (pcIP)> PASS *************** 
userID (pcIP)> 230 Logged on 
userID (pcIP)> OPTS utf8 on 
userID (pcIP)> 202 UTF8 mode is always enabled. No need to send this command. 
userID (pcIP)> PWD 
userID (pcIP)> 257 "/" is current directory. 
userID (pcIP)> TYPE I 
userID (pcIP)> 200 Type set to I 
userID (pcIP)> PASV 
userID (pcIP)> 227 Entering Passive Mode ((pcIP)) 
userID (pcIP)> STOR myTempDoc.pdf 
userID (pcIP)> 150 Opening data channel for file upload to server of "/myTempDoc.pdf" 
userID (pcIP)> 226 Successfully transferred "/myTempDoc.pdf" 

唯一的區別是,在第一種情況下,我不能上傳所需的文件。這裏有什麼區別?

uploadX(string path) 
{ 
    string host = "ftp://ip:port/"; 
    string user = "userID"; 
    string pass = "password"; 
    WebClient Xclient = new System.Net.WebClient(); 
    Uri uri = new Uri(host + new FileInfo(path).Name); 
    Xclient.Credentials = new System.Net.NetworkCredential(user, pass); 
    Xclient.UploadFileAsync(uri, "STOR", path); 
} 

而在我的主要功能我呼籲uploadX("docName")

+0

也許分享您的上傳功能的一些C#代碼? – rinukkusu

+0

檢查我更新的問題。 –

+0

什麼是錯誤信息? –

回答

1

您並未等待上傳完成。因此,如果這是一個在uploadX返回後不久退出的小型獨立腳本,則在腳本/應用程序完成之前,上傳可能完全無法完成。這可能解釋不同機器上的隨機行爲。

確保您等待上傳完成。要麼通過捕獲UploadFileCompleted event,要麼通過簡單地使用阻止UploadFile method

+0

基本上問題出在防火牆上。按照http://www.howtogeek.com/140352/how-to-host-an-ftp-server-on-windows-with-filezilla/中的說明,將端口添加到例外。但是,只有當我關閉防火牆時,我才設法發送文件。 –

+0

然後你的問題是[off-topic](http://stackoverflow.com/help/on-topic)堆棧溢出。 –

+0

但是,我將端口添加到防火牆中的例外列表中,因此它不會是防火牆問題。 –

1

您是否檢查過防火牆以確保數據端口已打開?

由於它正在切換PASV模式,FTP服務器應該發送一個新的端口進行通信。通常這些數據端口是1024到5000.

關閉Windows防火牆以查看它是否解決了問題。如果是這樣,請打開防火牆中的上述端口,或告訴FileZilla在設置中使用特定的一組端口並打開這些端口。

+0

基本上問題出在防火牆上。按照http://www.howtogeek.com/140352/how-to-host-an-ftp-server-on-windows-with-filezilla/中的說明,將端口添加到例外。但是,只有當我關閉防火牆時,我才設法發送文件。 –