2015-11-23 35 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/中的说明,将端口添加到例外。但是,只有当我关闭防火墙时,我才设法发送文件。 –