FTP 文件传输挂起并超时

FTP 文件传输挂起并超时

我在通过 FTP 上传文件时遇到了问题。我可以成功列出目录,但当我尝试上传文件(比如“.htaccess”)时,它会挂起大约 20 秒STOR .htacess,然后抛出超时。它重试了几次,但总是失败。

这是 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

这是在 iptbles 关闭的情况下发生的,所以这不是防火墙问题。文件大小肯定不是问题,因为它只有一行目录索引设置。

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

以下是一些补充说明:

vsftpd 日志中的一行显示:

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

,因此它声称转移已完成,但事实并非如此。

删除文件正常

演出概要tcpdump port ftp

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

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

答案1

首先,您可能想要测试不使用被动模式,以防您的整个设置可以使用它。

其次,看一下这一行:

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

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

请注意,如果没有全部信息,回答此类问题会很困难,但我希望这能为您提供一些指导。

答案2

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

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

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

我可以想象您遇到的问题有以下原因:

  1. 服务器出现了一些奇怪的问题。
  2. 中间有一些深度检查中间件(如防火墙),它们会根据策略或由于错误而主动干扰流量。一些防火墙禁止上传,以保护数据泄漏。
  3. 一些防火墙对数据连接的数量进行速率限制。
  4. 一些损坏的路由器在传输过程中使用的一些 TCP 选项出现故障。

我建议您采取以下步骤来缩小原因范围:

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

除此之外,我建议使用 SFTP(通过 SSH 进行文件传输),因为它更安全(加密登录)并且麻烦更少(只有单个连接,没有额外的数据连接)。

答案3

看起来只允许与 20000 以下的端口建立传出连接。确保客户端的传出和服务器的传入在 FTP 服务器的整个 PASV 范围内都是允许的。如果您在那里找不到范围,1024-65535 应该可以。

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

相关内容