是什么导致我的连接断开以及为什么?
服务器和客户端之间通过 FTPeS 下载文件每次都会在完全相同的文件数量处停止,没有任何提示取消连接的原因。无论文件有多大或下载这些文件需要多长时间,都无关紧要。服务器端使用哪种服务器软件并不重要,客户端软件也是如此。我在服务器端尝试使用 Microsoft IIS FTP 和 FileZilla Server,在客户端尝试使用 FileZilla Client、WinSCP 和自写客户端 (Delphi)。
在我的示例中,服务器机器 A 和客户端机器 B 之间正好有 296 个 txt 文件。服务器机器 A 和客户端机器 C 之间是另一个数量,但却是恒定/稳定/不变的。
服务器端网络
WAN 连接是德国 ISP Deutsche Telekom AG,VDSL2,具有伪静态公共 IP 地址(持续约一个月,之后会更改)。路由器和硬件防火墙是德国常见的 FRITZ!Box 7590,带有 FRITZ!OS:07.01。
我已经为 FTP 控制通道和被动模式数据通道配置了端口转发。
- 控制通道:TCP 21 外部到 21 内部
- 数据通道:TCP 50000-50010 外部至 50000-50010 内部
服务器
服务器机器是 Microsoft Windows 10 Pro 1903(10.0.18362 N/A Build 18362.239),通过 1 Gbps Cat5e FTP 电缆与路由器连接。
Windows Defender 防火墙
我已经在 Windows Defender 防火墙上打开了所需的端口。
Microsoft IIS FTP 配置
IIS 正在监听 TCP 端口 21 上的控制通道。数据通道设置为 TCP 50000-50010,以符合端口转发。控制通道和数据通道都需要 SSL 连接。
FileZila 服务器
相同的配置需要配置。TCP 端口 21(控制)、50000-50010(数据)。
客户
这是通过 IIS 下载时的 FileZilla 客户端日志。
2019-08-04 02:21:44 8736 3 Response: 226 Transfer complete.
2019-08-04 02:21:44 8736 3 Status: File transfer successful, transferred 4.096 bytes in 1 second
2019-08-04 02:21:44 8736 2 Response: 227 Entering Passive Mode (84,145,49,252,195,87).
2019-08-04 02:21:44 8736 2 Command: RETR random_file_433.txt
2019-08-04 02:21:44 8736 3 Status: Starting download of /Files/random_file_432.txt
2019-08-04 02:21:44 8736 3 Command: PASV
2019-08-04 02:21:44 8736 2 Response: 150 Opening BINARY mode data connection.
2019-08-04 02:21:44 8736 3 Response: 227 Entering Passive Mode (84,145,49,252,195,88).
2019-08-04 02:21:44 8736 3 Command: RETR random_file_432.txt
2019-08-04 02:21:44 8736 3 Error: Disconnected from server: ECONNABORTED - Connection aborted
2019-08-04 02:21:44 8736 3 Error: File transfer failed
2019-08-04 02:21:44 8736 3 Status: Disconnected from server
2019-08-04 02:21:44 8736 2 Response: 226 Transfer complete.
2019-08-04 02:21:44 8736 2 Status: File transfer successful, transferred 6.103 bytes in 1 second
2019-08-04 02:21:44 8736 3 Status: Resolving address of home.zaffran.de
2019-08-04 02:21:44 8736 2 Status: Starting download of /Files/random_file_431.txt
2019-08-04 02:21:44 8736 2 Command: PASV
2019-08-04 02:21:44 8736 2 Response: 227 Entering Passive Mode (84,145,49,252,195,89).
2019-08-04 02:21:44 8736 2 Command: RETR random_file_431.txt
2019-08-04 02:21:44 8736 3 Status: Connecting to 84.145.49.252:21...
2019-08-04 02:21:44 8736 2 Error: Disconnected from server: ECONNABORTED - Connection aborted
2019-08-04 02:21:44 8736 2 Error: File transfer failed
2019-08-04 02:21:44 8736 3 Status: Connection established, waiting for welcome message...
2019-08-04 02:21:44 8736 2 Status: Disconnected from server
2019-08-04 02:21:44 8736 2 Status: Resolving address of home.zaffran.de
2019-08-04 02:21:44 8736 2 Status: Connecting to 84.145.49.252:21...
2019-08-04 02:21:44 8736 3 Response: 220 Microsoft FTP Service
2019-08-04 02:21:44 8736 3 Command: AUTH TLS
2019-08-04 02:21:44 8736 2 Status: Connection established, waiting for welcome message...
2019-08-04 02:21:44 8736 3 Response: 234 AUTH command ok. Expecting TLS Negotiation.
2019-08-04 02:21:44 8736 3 Status: Initializing TLS...
2019-08-04 02:21:44 8736 2 Response: 220 Microsoft FTP Service
2019-08-04 02:21:44 8736 2 Command: AUTH TLS
2019-08-04 02:21:44 8736 2 Response: 234 AUTH command ok. Expecting TLS Negotiation.
这是通过 FileZilla Server 下载时的 FileZilla 客户端日志
2019-08-04 10:57:35 3724 2 Response: 226 Successfully transferred "/Files/random_file_596.txt"
2019-08-04 10:57:35 3724 2 Status: File transfer successful, transferred 1.024 bytes in 1 second
2019-08-04 10:57:35 3724 2 Status: Starting download of /Files/random_file_594.txt
2019-08-04 10:57:35 3724 2 Command: PASV
2019-08-04 10:57:35 3724 3 Response: 150 Opening data channel for file download from server of "/Files/random_file_595.txt"
2019-08-04 10:57:35 3724 2 Response: 227 Entering Passive Mode (84,145,49,252,195,80)
2019-08-04 10:57:35 3724 2 Command: RETR random_file_594.txt
2019-08-04 10:57:35 3724 3 Response: 226 Successfully transferred "/Files/random_file_595.txt"
2019-08-04 10:57:35 3724 3 Status: File transfer successful, transferred 2.048 bytes in 1 second
2019-08-04 10:57:35 3724 3 Status: Starting download of /Files/random_file_593.txt
2019-08-04 10:57:35 3724 3 Command: PASV
2019-08-04 10:57:35 3724 3 Response: 227 Entering Passive Mode (84,145,49,252,195,90)
2019-08-04 10:57:35 3724 3 Command: RETR random_file_593.txt
2019-08-04 10:57:35 3724 2 Error: Disconnected from server: ECONNABORTED - Connection aborted
2019-08-04 10:57:35 3724 2 Error: File transfer failed
2019-08-04 10:57:35 3724 3 Error: Disconnected from server: ECONNABORTED - Connection aborted
2019-08-04 10:57:35 3724 3 Error: File transfer failed
2019-08-04 10:57:35 3724 2 Status: Disconnected from server
2019-08-04 10:57:35 3724 2 Status: Resolving address of home.zaffran.de
2019-08-04 10:57:35 3724 2 Status: Connecting to 84.145.49.252:21...
2019-08-04 10:57:35 3724 2 Status: Connection established, waiting for welcome message...
2019-08-04 10:57:35 3724 3 Status: Disconnected from server
2019-08-04 10:57:35 3724 3 Status: Resolving address of home.zaffran.de
2019-08-04 10:57:35 3724 3 Status: Connecting to 84.145.49.252:21...
2019-08-04 10:57:35 3724 2 Response: 220 Muhahahaaa
2019-08-04 10:57:35 3724 2 Command: AUTH TLS
2019-08-04 10:57:35 3724 3 Status: Connection established, waiting for welcome message...
2019-08-04 10:57:35 3724 2 Response: 234 Using authentication type TLS
2019-08-04 10:57:35 3724 2 Status: Initializing TLS...
2019-08-04 10:57:35 3724 3 Response: 220 Muhahahaaa
2019-08-04 10:57:35 3724 3 Command: AUTH TLS
2019-08-04 10:57:35 3724 3 Response: 234 Using authentication type TLS
2019-08-04 10:57:35 3724 3 Status: Initializing TLS...
2019-08-04 10:57:35 3724 2 Status: Verifying certificate...
2019-08-04 10:57:35 3724 2 Status: TLS connection established.
2019-08-04 10:57:35 3724 2 Command: USER test
2019-08-04 10:57:35 3724 2 Response: 331 Password required for test
2019-08-04 10:57:35 3724 2 Command: PASS *******
2019-08-04 10:57:35 3724 3 Status: Verifying certificate...
2019-08-04 10:57:35 3724 3 Status: TLS connection established.
2019-08-04 10:57:35 3724 3 Command: USER test
2019-08-04 10:57:35 3724 2 Response: 230 Logged on
2019-08-04 10:57:35 3724 2 Command: PBSZ 0
2019-08-04 10:57:35 3724 3 Response: 331 Password required for test
2019-08-04 10:57:35 3724 3 Command: PASS *******
2019-08-04 10:57:35 3724 2 Response: 200 PBSZ=0
2019-08-04 10:57:35 3724 2 Command: PROT P
2019-08-04 10:57:35 3724 3 Response: 230 Logged on
2019-08-04 10:57:35 3724 3 Command: PBSZ 0
2019-08-04 10:57:35 3724 2 Response: 200 Protection level set to P
2019-08-04 10:57:35 3724 2 Status: Logged in
2019-08-04 10:57:35 3724 3 Response: 200 PBSZ=0
2019-08-04 10:57:35 3724 3 Command: PROT P
2019-08-04 10:57:35 3724 2 Status: Starting download of /Files/random_file_592.txt
2019-08-04 10:57:35 3724 2 Command: CWD /Files
2019-08-04 10:57:35 3724 3 Response: 200 Protection level set to P
2019-08-04 10:57:35 3724 3 Status: Logged in
2019-08-04 10:57:35 3724 2 Response: 250 CWD successful. "/Files" is current directory.
2019-08-04 10:57:35 3724 2 Command: TYPE I
2019-08-04 10:57:35 3724 3 Status: Starting download of /Files/random_file_591.txt
2019-08-04 10:57:35 3724 3 Command: CWD /Files
2019-08-04 10:57:35 3724 2 Response: 200 Type set to I
2019-08-04 10:57:35 3724 2 Command: PASV
2019-08-04 10:57:35 3724 3 Response: 250 CWD successful. "/Files" is current directory.
2019-08-04 10:57:35 3724 3 Command: TYPE I
2019-08-04 10:57:35 3724 2 Response: 227 Entering Passive Mode (84,145,49,252,195,81)
使用 WinSCP 通过 FileZilla Server 下载时的样子如下
这是我自己编写的 Delphi FTP 客户端通过 FileZilla Server 下载时的日志
Sent 04.08.2019 11:06:52: RETR random_file_297.txt<EOL>
Recv 04.08.2019 11:06:52: 150 Opening data channel for file download from server of "/Files/random_file_297.txt"<EOL>
Recv 04.08.2019 11:06:52: 226 Successfully transferred "/Files/random_file_297.txt"<EOL>
Sent 04.08.2019 11:06:53: PASV<EOL>
Recv 04.08.2019 11:06:53: 227 Entering Passive Mode (84,145,49,252,195,84)<EOL>
Sent 04.08.2019 11:06:53: RETR random_file_298.txt<EOL>
Recv 04.08.2019 11:06:53: 150 Opening data channel for file download from server of "/Files/random_file_298.txt"<EOL>
Recv 04.08.2019 11:06:53: 226 Successfully transferred "/Files/random_file_298.txt"<EOL>
Sent 04.08.2019 11:06:53: PASV<EOL>
Recv 04.08.2019 11:06:53: 227 Entering Passive Mode (84,145,49,252,195,85)<EOL>
Sent 04.08.2019 11:06:53: RETR random_file_299.txt<EOL>
Recv 04.08.2019 11:06:53: 150 Opening data channel for file download from server of "/Files/random_file_299.txt"<EOL>
Stat Disconnected.
Stat Disconnected.