FTP文件传输挂起并超时

我有一个文件通过FTP上传的问题。 我可以成功地列出目录,但是当我尝试上传文件时,让我们说“.htaccess”,它挂在STOR .htacess约20秒,然后抛出一个超时。 它重试多次,但总是失败。

这是FTP客户端的完整输出如何进行文件传输:

 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 

这与iptblesclosures,所以这不是一个防火墙问题。 文件的大小肯定不是问题,因为它只是一个目录索引设置的行。

另外需要注意的是,这是一个chrome目录,由codebuster拥有:codebuster和权限是drwxrw-rw-

这里是一些额外的说明:

来自vsftpd日志的一行显示:

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

,所以它声称转让是完整的,但事实并非如此。

删除文件正常工作

tcpdump port ftp总结tcpdump port ftp显示:

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

在FTP客户端中使用主动模式不会改变情况。

首先,你可能想testing不使用被动模式,以防万一你的整个设置工作。

其次,看看这一行:

回应:227进入被动模式(88,150,168,207,155,25)。

这是VPS的IP地址加上两个数字,我们称之为p1和p2。 这些数字通过遵循公式“port =(p1 * 256)+ p2”告诉你应该连接的端口。 基于此,我build议您在计算机和VPS上同时捕获networking,以查看问题出在哪里。 如果您发现从您的计算机启动的被动端口上的连接但未到达VPS,则问题可能出在您的本地networking上(正如您所说,VPS前没有防火墙)。 如果数据包到达服务器,但没有回复,则问题可能出在服务器上的FTP设置上。

请注意,如果没有所有的信息,回答这样的问题是困难的,但我希望这给你一些指导。

我可以成功地列出目录,但是当我尝试上传文件时,它会挂起大约20秒钟…然后抛出超时。

目录列表和文件传输使用相同的基本机制,即打开数据连接和传输数据。 在你的情况下,客户端在PASV命令的响应中打开到服务器指定的地址的连接。

由于目录列表工作,排除了所有数据连接被防火墙或NAT设备阻止的常见情况。

我可以想象你有这个问题的原因如下:

  1. 服务器上有一些奇怪的问题。
  2. 一些深度检测中间件(如防火墙),它们之间通过策略或错误主动干扰stream量。 一些防火墙禁止上传作为数据泄漏保护。
  3. 一些防火墙限制了数据连接的数量。
  4. 一些破碎的路由器呱呱在传输过程中使用的一些TCP选项。

我build议你采取以下步骤来缩小原因:

  • 查看FTP服务器的日志文件,查看是否有任何问题报告。
  • 尝试在VPS本身(到本地系统)上的被动FTP连接。
  • 尝试从另一个位置。
  • 尝试在相同的FTP会话之后做多个目录列表。
  • 尝试从服务器获取文件以查看是否只有上传受到影响。

除此之外,我build议使用SFTP(通过SSH进行文件传输),因为它更安全(encryptionlogin),导致更less的麻烦(只有一个连接,没有额外的数据连接)。

看起来只有20000以下端口的传出连接才被允许。 确保客户端上的传出和服务器上的传入被允许在FTP服务器的整个PASV范围内。 如果你不能find范围,1024-65535应该工作。

 >>> 155*256+25 39705 >>> 73*256+43 #OK 18731 >>> 222*256+74 56906 >>> 35*256+185 #OK 9145 >>> 109*256+53 27957