使用 ASCII 模式通过 FTP 传输 UTF-8 文件?

Transfer UTF-8 file over FTP using ASCII mode?

问题说明了一切。是否可以使用 ASCII 模式通过 FTP 传输 UTF-8 文件?还是会导致字符写错?谢谢!

RFC 2640, from 1999, updates the FTP protocol to support internationalization. It requires FTP servers to use UTF-8 as the transfer encoding in section 2.2. So as long as you aren't trying to upload to a DEC TOPS-20 server (which stores five 7-bit bytes within a 36-bit word), 你应该没事的。

  1. UTF-8 编码旨在向后兼容 ASCII 编码。

  2. RFC 959 要求 FTP 客户端和服务器将 ASCII 模式的文件视为 8 位:

    3.1.1.1. ASCII TYPE

    ...

    The sender converts the data from an internal character representation to the standard 8-bit NVT-ASCII representation (see the Telnet specification). The receiver will convert the data from the standard form to his own internal form.

    In accordance with the NVT standard, the sequence should be used where necessary to denote the end of a line of text. (See the discussion of file structure at the end of the Section on Data Representation and Storage.)

    ...

    Using the standard NVT-ASCII representation means that data must be interpreted as 8-bit bytes.


因此,即使 UTF-8 不知道 FTP 客户端或服务器也应该正确转换行尾,因为它们在 ASCII 和 UTF-8 中的编码相同。而且他们不应该破坏其他角色。


从实际的角度来看:我还没有遇到过确实有 8 位文本文件问题的服务器。我是捷克人,所以我经常使用 UTF-8,过去使用 Windows-1250 和 ISO/IEC 8859-2 8 位编码。