2014-05-10 67 views
1

我正在写一个FTP服务器(用Qt/C++),现在我用“200 Ok”改为“TYPE A”,但我真的把它和“类型I“ - 文件按原样发送。在FTP服务器中实现“TYPE A”

我应该如何正确实施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. 
+0

你是什么意思'我返回成功的类型A''? “我应该如何正确实施A型”是什么意思?你的问题目前假设了太多的知识,而不是像我的那样。 ;) – lpapp

+0

这就是命令的命名方式。在控制连接中写入“TYPE A”以指定ASCII,“TYPE I”代表Image - 表示二进制。 – sashoalm

+0

@LaszloPapp:确定存在:在RFC959第27页中描述了类型A(ASCII),I(图像)和E(EBCDIC)。 –

回答

3

使用ASCII模式(A类),你需要在打开文件传输文件文本模式,然后用结束CRLF的行传送它们。如果您执行SIZE命令,则需要根据传输类型报告大小。因为扫描整个文件的开销显然太大,只是为了获得大小正确的服务器,如果该命令不是在映像模式下使用的,经常会返回550 SIZE not allowed in ASCII mode

+0

谢谢。顺便说一句,我看起来太懒惰了,因为当我终于找到节录的时候,它就在那里。我猜这个网站在这里帮了我一个橡皮鸭:) – sashoalm