FTP file transfer hangs and times out

centos7ftpuploadvps

I have an issue with file upload via FTP. I can successfuly list the directories, but when I try to upload a file, let's say ".htaccess", it hangs for about 20 seconds on STOR .htacess, and then throws a timeout. It retries several times but always fails.

This is how a full output from FTP client looks like for file transfer:

Status: Connecting to 88.150.168.207:21...
Status: Connection established, waiting for welcome message...
Response:   220 Welcome to CodeBuster FTP service.
Command:    USER codebuster
Response:   331 Please specify the password.
Command:    PASS ********
Response:   230 Login successful.
Command:    OPTS UTF8 ON
Response:   200 Always in UTF8 mode.
Status: Connected
Status: Starting upload of D:\Projects\codebuster\.htacess
Command:    CWD /public_html
Response:   250 Directory successfully changed.
Command:    PWD
Response:   257 "/public_html"
Command:    TYPE A
Response:   200 Switching to ASCII mode.
Command:    PASV
Response:   227 Entering Passive Mode (88,150,168,207,155,25).
Command:    STOR .htacess
Error:  Connection timed out
Error:  File transfer failed
Status: Connecting to 88.150.168.207:21...
Status: Connection established, waiting for welcome message...
Response:   220 Welcome to CodeBuster FTP service.
Command:    USER codebuster
Response:   331 Please specify the password.
Command:    PASS ********
Response:   230 Login successful.
Command:    OPTS UTF8 ON
Response:   200 Always in UTF8 mode.
Status: Connected
Status: Starting upload of D:\Projects\codebuster\.htacess
Command:    CWD /public_html
Response:   250 Directory successfully changed.
Status: Retrieving directory listing...
Command:    TYPE I
Response:   200 Switching to Binary mode.
Command:    PASV
Response:   227 Entering Passive Mode (88,150,168,207,73,43).
Command:    LIST
Response:   150 Here comes the directory listing.
Response:   226 Directory send OK.
Command:    TYPE A
Response:   200 Switching to ASCII mode.
Command:    PASV
Response:   227 Entering Passive Mode (88,150,168,207,222,74).
Command:    STOR .htacess
Error:  Connection timed out
Error:  File transfer failed
Status: Connecting to 88.150.168.207:21...
Status: Connection established, waiting for welcome message...
Response:   220 Welcome to CodeBuster FTP service.
Command:    USER codebuster
Response:   331 Please specify the password.
Command:    PASS ********
Response:   230 Login successful.
Command:    OPTS UTF8 ON
Response:   200 Always in UTF8 mode.
Status: Connected
Status: Starting upload of D:\Projects\codebuster\.htacess
Command:    CWD /public_html
Response:   250 Directory successfully changed.
Status: Retrieving directory listing...
Command:    TYPE I
Response:   200 Switching to Binary mode.
Command:    PASV
Response:   227 Entering Passive Mode (88,150,168,207,35,185).
Command:    LIST
Response:   150 Here comes the directory listing.
Response:   226 Directory send OK.
Command:    TYPE A
Response:   200 Switching to ASCII mode.
Command:    PASV
Response:   227 Entering Passive Mode (88,150,168,207,109,53).
Command:    STOR .htacess
Error:  Connection timed out
Error:  File transfer failed

This is with iptbles off, so it's not a firewall issue. Size of the file is surely not an issue, as it's just one line with directory index setting.

As an additional note, this is a chrot directory, owned by codebuster:codebuster and permissions are drwxrw-rw-.

Here are some additional notes:

a line from vsftpd log shows:

Sat Jan 10 14:46:23 2015 240 ::ffff:89.72.176.192 35 /public_html/.htacess a _ i r codebuster ftp 0 * c

, so it claims that the transfer was complete, but it was not.

Deleting files works correctly

Summary of tcpdump port ftp shows:

100 packets captured
101 packets received by filter
0 packets dropped by kernel

Using active mode in ftp client does not change the situation.

Best Answer

Firstly you may want to test not using passive mode, just in case your whole setup works with it.

Secondly, have a look at this line:

Response: 227 Entering Passive Mode (88,150,168,207,155,25).

That's the IP address of the VPS plus two more numbers, let's call them p1 and p2. These numbers are telling you the port where you should be connecting to, by following the formula "port=(p1*256)+p2". Based on that I'd recommend you to get simultaneous network captures on your computer and the VPS to see where the issue is. If you see the connection on the passive port initiated from your computer but not reaching the VPS, then the problem may be on your local network (as you said there's no firewall in front of your VPS). If the packets get to the server but it doesn't reply, the problem may be on your FTP setup on the server.

Please mind that answering this kind of questions is difficult without all the information, but I hope this gives you some guidance.