我正在编写一个 FTP 服务器(在 Qt/C++ 中),现在我将“200 Ok”设置为“TYPE A”,但我真的将其视为与“TYPE I”相同 - 文件发送为 -是。
我应该如何正确实现 TYPE A?以文本模式而不是二进制模式打开文件就足够了吗?
此外,我假设 SIZE 方法应该比返回磁盘上文件的大小更复杂,它应该读取它并执行文本替换,然后以这种方式返回大小?
编辑:为回应评论,这里是the RFC959 spec 的相关摘录。 :
3.1.1.1. ASCII TYPE This is the default type and must be accepted by all FTP implementations. It is intended primarily for the transfer of text files, except when both hosts would find the EBCDIC type more convenient. 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 <CRLF> 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. The Format parameter for ASCII and EBCDIC types is discussed below.
最佳答案
要使用 ASCII 模式(类型 A)传输文件,您需要以文本模式打开文件,然后使用行尾 CRLF 传输它们。如果您实现 SIZE 命令,您将需要根据传输类型报告大小。因为如果不在图像模式下使用该命令,服务器通常会返回 550 SIZE not allowed in ASCII mode
显然开销太大而仅仅为了获得正确的大小而扫描整个文件。
关于c++ - 在 FTP 服务器中实现 "TYPE A",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23579916/