简体   繁体   English

在FTP服务器中实现“TYPE A”

[英]Implementing “TYPE A” in an FTP server

I'm writing an FTP server (in Qt/C++), and right now I with "200 Ok" to "TYPE A", but I really treat it the same as "TYPE I" - files are sent as-is. 我正在写一个FTP服务器(在Qt / C ++中),现在我用“200 Ok”到“TYPE A”,但我真的把它当作“TYPE I” - 文件按原样发送。

How should I go about properly implementing TYPE A? 我该如何正确实施TYPE? Would opening the files in text mode instead of binary mode be enough? 以文本模式而不是二进制模式打开文件是否足够?

Also, I assume that the SIZE method should be more complex than returning the file's size on disk, it should read it and perform the text substitutions, and return the size that way? 另外,我假设SIZE方法应该比在磁盘上返回文件的大小更复杂,它应该读取它并执行文本替换,并以这种方式返回大小?

Edit: In response to a comment, here's the relevant excerpt from the RFC959 spec : 编辑:在回复评论时,这是RFC959规范的相关摘录:

  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. 

For transferring files with ASCII mode (type A) you would need to open the files in text mode and then transfer them with line ending CRLF. 要使用ASCII模式(类型A)传输文件,您需要以文本模式打开文件,然后使用行结束CRLF传输它们。 If you implement the SIZE command you would be required to report the size according to the transfer type. 如果实施SIZE命令,则需要根据传输类型报告大小。 Because this is obviously too much overhead to scan the whole file just for getting the size right server often return 550 SIZE not allowed in ASCII mode if the command is used not in image mode. 因为这显然是扫描整个文件的过多开销只是为了获得正确的大小服务器550 SIZE not allowed in ASCII mode如果命令不在图像模式下使用,则通常550 SIZE not allowed in ASCII mode返回550 SIZE not allowed in ASCII mode

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM