# 文件传输协议

**文件传输协议**（File Transfer Protocol，FTP）是一种在 TCP 之上于客户端与服务器之间传输文件的标准网络协议，其现行形式由 1985 年 10 月的 RFC 959 定义，并被指定为 STD 9。<sup>[1](https://www.rfc-editor.org/info/rfc959/)</sup> 它使用两条独立的连接——一条用于传输命令的控制通道和一条用于传输文件内容的数据通道——在其基本形式中，命令、凭据和数据均以明文传输。<sup>[2](https://censys.com/blog/ftp-exposure-brief/)</sup> 加密变体（FTPS）以及一个名称相似但与之无关的、基于 SSH 的协议（SFTP）如今承载了大多数安全文件传输工作负载。<sup>[3](https://sftphub.com/blog/sftp-vs-ftps-vs-ftp/)</sup>

| 关键事实 | 详情 |
|---|---|
| 现行规范 | RFC 959，1985 年 10 月，由 J. Postel 和 J. Reynolds 编写；废弃 RFC 765；由 RFC 2228、2640、2773、3659、5797 和 7151 更新<sup>[1](https://www.rfc-editor.org/info/rfc959/)</sup> |
| 连接模型 | 两条 TCP 通道：控制通道使用端口 21，数据通道在主动模式下使用端口 20，在被动模式下使用协商端口<sup>[4](https://docs.cpanel.net/knowledge-base/ftp/how-to-enable-ftp-passive-mode/)</sup> |
| 加密 | 基本 FTP 无加密；FTPS 通过 AUTH TLS 命令添加 TLS（RFC 4217，2005 年 10 月）<sup>[5](https://datatracker.ietf.org/doc/rfc4217/)</sup> |
| 已记录的攻击 | 通过代理 FTP 实施的反弹攻击、使用 PASS 命令的明文密码传输，以及端口窃取（RFC 2577，1999 年 5 月）<sup>[6](https://datatracker.ietf.org/doc/html/rfc2577)</sup> |
| 互联网暴露情况（2026 年 4 月） | 约 595 万台面向互联网的 FTP 主机，较 2024 年的 1010 万台下降 40%；58.9% 显示完成了 TLS 握手，约 245 万台未显示任何加密迹象<sup>[2](https://censys.com/blog/ftp-exposure-brief/)</sup> |
| 最常见的服务器 | Pure-FTPd（约 199 万个服务）、ProFTPD（81.2 万）、vsftpd（37.9 万）、IIS（25.9 万）、FileZilla Server（约 18.4 万）<sup>[7](https://www.securityweek.com/half-of-the-6-million-internet-facing-ftp-servers-lack-encryption/)</sup> |

## 历史

FTP 起源于 ARPANET。开发始于 1971 年 RFC 114 的发表，1971 年 11 月 17 日的 RFC 265 将 FTP 描述为一种用户级协议，用于在 ARPANET 上的主机计算机之间传输文件，使用 RFC 264 的数据传输协议。<sup>[8](https://www.ietf.org/ietf-ftp/rfc/rfc265.txt.pdf)</sup> 1970 年代初随之进行了一系列修订，而至今仍被引为基本规范的 RFC 959 版本于 1985 年 10 月由 ISI 的 [Jon Postel](https://www.edgepedia.org/zh/jon-postel) 和 Joyce Reynolds 发表。<sup>[1](https://www.rfc-editor.org/info/rfc959/)</sup>

RFC 959 是被更新而非被取代。所列更新包括 RFC 2228（FTP 安全扩展，1997 年）、RFC 2640（国际化）、RFC 3659（扩展）、RFC 5797（命令注册表）和 RFC 7151（虚拟主机）。<sup>[1](https://www.rfc-editor.org/info/rfc959/)</sup>

## 协议工作原理

FTP 将控制与数据分离。客户端向服务器打开一条控制连接，通常使用 TCP 端口 21，命令和三位数字的回复代码以 Telnet 风格的文本在此连接上传输。文件内容和目录列表则通过一条独立的数据连接传输。<sup>[1](https://www.rfc-editor.org/info/rfc959/)</sup>

**主动模式。** 在主动数据连接中，客户端发送 PORT 命令，告知服务器应回连到哪个地址和端口，由服务器发起数据连接，通常从其端口 20 发起。<sup>[4](https://docs.cpanel.net/knowledge-base/ftp/how-to-enable-ftp-passive-mode/)</sup><sup> • </sup><sup>[9](https://learn.microsoft.com/iis/publish/using-the-ftp-service/configuring-ftp-firewall-settings-in-iis-7)</sup> 主动连接曾经是默认方式，但它们在互联网上效果不佳，因为服务器必须能够到达客户端，而客户端防火墙和 NAT 通常会阻止这种连接。<sup>[9](https://learn.microsoft.com/iis/publish/using-the-ftp-service/configuring-ftp-firewall-settings-in-iis-7)</sup>

**被动模式。** 在被动模式下，服务器为数据通道打开一个端口并监听；由客户端发起连接。RFC 1579《对防火墙友好的 FTP》推荐使用被动模式，它在互联网场景中效果要好得多。<sup>[9](https://learn.microsoft.com/iis/publish/using-the-ftp-service/configuring-ftp-firewall-settings-in-iis-7)</sup> 代价是服务器必须暴露一段被动数据端口范围；例如，cPanel 默认为 Pure-FTPd 和 ProFTPD 启用 49152 至 65534 的被动端口，使用 nftables、firewalld 或 iptables 的管理员必须手动开放该范围。<sup>[4](https://docs.cpanel.net/knowledge-base/ftp/how-to-enable-ftp-passive-mode/)</sup>

**NAT 交互。** 当客户端位于 NAT 之后时，主动 FTP 会失效：PORT 命令携带客户端的私有 IP 地址，而该地址无法更改，因此流量经过转换后，服务器看到的是一个无效地址。微软将此描述为主动 FTP 与客户端 NAT 配合时的一般性限制，并建议此类部署使用被动模式。<sup>[10](https://learn.microsoft.com/en-us/azure/firewall/ftp-support)</sup> NAT 之后的被动模式需要转发被动端口范围，并配置服务器对外通告其外部地址。<sup>[4](https://docs.cpanel.net/knowledge-base/ftp/how-to-enable-ftp-passive-mode/)</sup>

## 扩展

RFC 3659《FTP 扩展》（2007 年 3 月，P. Hethmon，Hethmon Software）以规定格式的机器可读目录列表命令（MLST 和 MLSD）以及重启中断传输的命令（REST）更新了 RFC 959。<sup>[11](https://www.rfc-editor.org/info/rfc3659/)</sup> FEAT 命令让客户端可以在使用之前发现服务器支持哪些扩展。<sup>[11](https://www.rfc-editor.org/info/rfc3659/)</sup>

## 安全

RFC 2577《FTP 安全考量》（1999 年 5 月）编录了该协议的弱点。代理 FTP——即客户端请求一台服务器从另一台服务器传输文件——使“反弹攻击”成为可能，该文档建议服务器拒绝指定 TCP 端口低于 1024 的 PORT 命令。标准 FTP 通过 PASS 命令以明文发送密码，该文档推荐使用不受窃听影响的认证机制。它还描述了端口窃取，即利用按递增顺序分配动态端口号的操作系统。<sup>[6](https://datatracker.ietf.org/doc/html/rfc2577)</sup>

**FTPS。** RFC 4217（2005 年 10 月，P. Ford-Hutchinson，IBM UK Ltd）规定了用 TLS 保护 FTP，建立在 RFC 2228 安全扩展之上。客户端发出 AUTH TLS 命令，服务器回复 234 以开始 TLS 握手，PROT 命令则协商数据连接的保护方式。<sup>[5](https://datatracker.ietf.org/doc/rfc4217/)</sup> 这就是“显式 FTPS”，它以端口 21 上的常规 FTP 连接开始，然后升级为 TLS。“隐式 FTPS”从一开始就将整个连接包裹在 TLS 中，通常使用端口 990，已被弃用且基本不再使用。<sup>[2](https://censys.com/blog/ftp-exposure-brief/)</sup>

**SFTP。** 尽管名称如此，SFTP（SSH 文件传输协议）根本不是 FTP。它是 SSH 的一个子系统，在端口 22 上通过单条加密通道运行，与 FTP 没有任何协议传承关系；名称上的重叠被描述为一场历史意外，已造成数十年的混淆。<sup>[2](https://censys.com/blog/ftp-exposure-brief/)</sup> 与 [FTPS](https://www.edgepedia.org/zh/ftps) 相比，SFTP 只需要一个端口，数据通道无需防火墙例外，这就是它成为替代 FTP 的常见默认推荐的原因。<sup>[2](https://censys.com/blog/ftp-exposure-brief/)</sup><sup> • </sup><sup>[3](https://sftphub.com/blog/sftp-vs-ftps-vs-ftp/)</sup>

## 当今部署

互联网情报公司 Censys 观察到，截至 2026 年 4 月，有略低于 600 万台主机（5,949,954 台）运行至少一项面向互联网的 FTP 服务，低于 2024 年的逾 1010 万台，两年下降 40%；FTP 仍占所有互联网可见系统的 2.72%。<sup>[2](https://censys.com/blog/ftp-exposure-brief/)</sup><sup> • </sup><sup>[7](https://www.securityweek.com/half-of-the-6-million-internet-facing-ftp-servers-lack-encryption/)</sup> 约 58.9% 的 FTP 主机至少有一项服务完成了 TLS 握手，其中 97% 使用 TLS 1.2 或 1.3。其余约 245 万台主机的任何 FTP 服务均未显示加密迹象。<sup>[2](https://censys.com/blog/ftp-exposure-brief/)</sup>

美国以约 120 万台 FTP 可见主机居首，其次是中国（86.6 万）、德国（46.7 万）、香港（41.5 万）、日本（36.6 万）和法国（34.3 万）。<sup>[7](https://www.securityweek.com/half-of-the-6-million-internet-facing-ftp-servers-lack-encryption/)</sup> TLS 采用率的地区差异显著：香港以 87% 的主机居首，而中国大陆（17.9%）和韩国（14.5%）在前十大托管国家中最低。<sup>[2](https://censys.com/blog/ftp-exposure-brief/)</sup>

**为何持续存在。** Censys 将大部分暴露归因于平台默认设置而非刻意选择：FTP 暴露最多的网络是大型共享主机和宽带提供商，而占主导地位的守护进程就是这些平台预装的。最常见的服务器 Pure-FTPd（约 199 万个服务）是 Linux 上 cPanel 的默认项；vsftpd 随大多数主流 Linux 发行版预装；IIS FTP 在任何启用了 FTP 角色的 [Windows Server](https://www.edgepedia.org/zh/windows-server) 上默认运行，有超过 15 万个 IIS 服务从未设置加密。<sup>[2](https://censys.com/blog/ftp-exposure-brief/)</sup><sup> • </sup><sup>[7](https://www.securityweek.com/half-of-the-6-million-internet-facing-ftp-servers-lack-encryption/)</sup> Censys 指出，在必须保留 FTP 的地方，启用显式 TLS 是一项配置更改而非协议升级，Pure-FTPd 和 vsftpd 都原生支持。<sup>[7](https://www.securityweek.com/half-of-the-6-million-internet-facing-ftp-servers-lack-encryption/)</sup>

## References

1. [RFC 959: File Transfer Protocol (STD 9), J. Postel and J. Reynolds, October 1985, RFC Editor](https://www.rfc-editor.org/info/rfc959/)
2. [FTP Exposure Brief: Examining the 55-Year-Old Protocol Used by Millions, Censys, April 2026](https://censys.com/blog/ftp-exposure-brief/)
3. [SFTP vs FTPS vs FTP: Which File Transfer Protocol Should You Use?, SFTPHub](https://sftphub.com/blog/sftp-vs-ftps-vs-ftp/)
4. [How to Enable FTP Passive Mode, cPanel & WHM Documentation](https://docs.cpanel.net/knowledge-base/ftp/how-to-enable-ftp-passive-mode/)
5. [RFC 4217: Securing FTP with TLS, P. Ford-Hutchinson, October 2005, IETF](https://datatracker.ietf.org/doc/rfc4217/)
6. [RFC 2577: FTP Security Considerations, Allman and Ostermann, May 1999, IETF](https://datatracker.ietf.org/doc/html/rfc2577)
7. [Half of the 6 Million Internet-Facing FTP Servers Lack Encryption, SecurityWeek, April 2026](https://www.securityweek.com/half-of-the-6-million-internet-facing-ftp-servers-lack-encryption/)
8. [RFC 265: File Transfer Protocol, 17 November 1971, IETF](https://www.ietf.org/ietf-ftp/rfc/rfc265.txt.pdf)
9. [Configuring FTP Firewall Settings in IIS 7, Microsoft Learn](https://learn.microsoft.com/iis/publish/using-the-ftp-service/configuring-ftp-firewall-settings-in-iis-7)
10. [Azure Firewall FTP support, Microsoft Learn](https://learn.microsoft.com/en-us/azure/firewall/ftp-support)
11. [RFC 3659: Extensions to FTP, P. Hethmon, March 2007, RFC Editor](https://www.rfc-editor.org/info/rfc3659/)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 17, 2026; Sep 30, 2026; Oct 15, 2026 · Edited: Sep 30, 2026; Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 网络与安全 › Networking fundamentals and architecture › Internet protocol suite

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/file-transfer-protocol

English original: https://www.edgepedia.org/file-transfer-protocol
