目录
基础知识
- FTP is a TCP based service exclusively. There is no UDP component to FTP.
- FTP is an unusual service in that it utilizes two ports, a ‘data’ port and a ‘command’ port (also known as the control port). Traditionally these are port 21 for the command port and port 20 for the data port.
- The data port is not always on port 20, depending on the mode(active mode and passive mode).
主动模式
1. Server 监听 21 端口,Client 使用随机端口 N(1026) 主动连接 Server 21 端口,并将端口 N+1(1027) 发送给 Server, 告诉 Server Client 监听 N+1 端口,用作数据传输。
2. Server 给 Client 回 ACK 包。
3. Server 使用端口 20 主动连接 Client 的 N+1 端口。
4. Client 给 Server 回 ACK 包。
主动模式的问题 - 局域网和防火墙
- 一般客户端处于局域网中,开启监听的数据传输用的地址是内网地址,外网 FTP server 连接该地址;
- 即使客户端直接使用外网 IP, 防火墙的配置也是个问题,因为客户端开启的数据传输监听端口是随机的,防火墙只能按 IP 配置,如果 FTP server 是一个接入了多个 IP 的域名,那按 IP 配置也将行不通。(Nowadays, it is typical that the client is behind a firewall (e.g. built-in Windows firewall) or NAT router (e.g. ADSL modem), unable to accept incoming TCP connections. FTP Connection Modes (Active vs. Passive))
被动模式
1. Server 监听 21 端口,Client 使用随机端口 N(1026) 主动连接 Server 21 端口,并告诉 Server 使用 PASV 模式。
2. Server 告诉 Client 使用随机端口 2024 作为数据传输端口。
3. Client 使用 N+1(1027) 端口连接 Server 2024 端口。
4. Server 给 Client ACK 包。
被动模式的问题
- 被动模式会使 Server 负载增