File is not uploaded to FTP server on some machine

2019-06-02 22:15发布

I am trying to upload files to a FileZilla FTP server. I have setup in my PC the server and I am using a simple C# script in order to upload files. It works properly when I run the script from the same machine. When I tried to run the script from another computer from the same or different LAN I got issues which are:

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

What could be caused the issues here? The message I am receiving from my own PC is the following:

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

The only difference is that in the first case I cant upload the desired file. What could be the difference here?

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);
}

And in my main function I call uploadX("docName").

2条回答
在下西门庆
2楼-- · 2019-06-02 22:31

Have you checked the firewalls to make sure the data ports are open?

Since it is switching PASV mode, the FTP server should be sending a new port to communicate on. Typically those data ports are 1024 to 5000.

Turn off the Windows firewalls to see if it fixes the issue. If it does, open the above ports in the firewall or tell FileZilla to use a specific set of ports in the settings and open those ports.

查看更多
看我几分像从前
3楼-- · 2019-06-02 22:41

You are not waiting for the upload to complete. So if this is a small standalone script that exits soon after the uploadX returns, the upload may not finish at all, before the script/application completes. That might explain the random behavior on different machines.

Make sure you wait for the upload to complete. Either by capturing UploadFileCompleted event, or simply by using a blocking UploadFile method.

查看更多
登录 后发表回答