2014-05-10 65 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