original link http://louisnetwork.blog.sohu.com/111930387.html
FTP這兩個mode比較冷僻,一般不會注意到這個,但今天被我遇到了,一定要研究下,
突然發現用xp-built的cmd去登某個FTP server下東西的時候,一定要手動去改成BIN mode,不然檔案下下來卻打不開,ftp server用的是linux系統.
而如果換成用browser去登這個FTP server的時候,抓包發現,ftp client會主動要求改成BIN mode,用位元組傳輸.
請教了一下高手,等到的答案是有些檔案必須用BIN來傳輸,ASCII碼大多給一般檔案等檔案來使用,BIN主要給exe檔,編碼過的檔案,不可重排置換內容的檔案.一般的FTP軟體都會通過副檔名來自動分類,判斷用ASCII來傳輸還是BIN來傳輸.
但是還是不甘心,不過詳細,終於在google上找到了一篇比較好的,引用一下,感謝那位大哥,
一般來說:
如果你用錯誤的模式傳輸你的圖片,你將會無法看到圖片,看到的會是亂碼。
如果你用錯誤模式上傳CGI指令碼,那麼就將無法運行你的指令碼,會看到類似Server 500 Error的出錯資訊。
所以你必須使用正確的模式,圖片和執行檔案必須用BINARY模式,CGI指令碼和普通HTML檔案用ASCII模式上傳.
ASCII和BINARY模式區別:
用HTML 和文本編寫的檔案必須用ASCII模式上傳,用BINARY模式上傳會破壞檔案,導致檔案執行出錯。
BINARY模式用來傳送可執行檔,壓縮檔,和圖片檔案。
如果你用ASCII模式傳,會顯示一堆亂碼,你必須重新用BINARY模式傳。對於第二種情況,是因為有很多ftp伺服器和用戶端軟體能自動識別檔案類型,並採取相應的傳輸方式。
ASCII模式和Binary模式的區別是斷行符號換行的處理,Binary模式不對資料進行任何處理,ASCII模式將斷行符號換行轉換為原生斷行符號字元,比如:UNIX下是/n,Windows下是/r/n,Mac下是/r。
ASCII 模式下會轉換檔,不能說是不同系統對斷行符號換行解釋不同,而是不同的系統有不同的行結束符。UNIX系統下行結束符是一個位元組,即十六進位的0A,而 Windows的系統是兩個位元組,即十六進位的0D0A,所以當你用ASCII方式從UNIX的FTP Server下載檔案到Windows系統上時(不管是二進位或者文字檔),每檢測到一個位元組是0A,就會自動插入一個0D,所以如果你的檔案是二進位 檔案,比如可執行檔、壓縮包什麼的,就肯定不能用了。如果你的檔案就是UNIX下的文字檔,你用ASCII模式是正確的,要是誤用了Binary模 式,你在Windows上看這個檔案是沒有換行的,裡面是一個個的黑方塊。一般來說,我們最好都用Binary方式,這樣可以保證不出錯。如果有文字格式設定轉換的問題,即UNIX格式的文本和DOS格式的文本之間的轉換,有很多工具可以做的,不要在ftp傳輸的時候冒險,尤其是你如果對這些東西不是非常清楚的話。如何設定FTP的傳輸方式呢?
在ftp>提示符下輸入ascii即轉換到ACSII方式,輸入bin,即轉換到Binary方式.
現在明白了把,xp-built不能自己選擇傳輸方式,而一般的ftp client,比如說browser就能夠自己根據副檔名來選擇用何種傳輸方式.
在wiki裡面兩個mode定義,如下,供參考,
Data format
While transferring data over the network, several data representations can be used. The two most common transfer modes are:
ASCII mode
Binary mode: In "Binary mode", the sending machine sends each file byte for byte and as such the recipient stores the bytestream as it receives it. (The FTP standard calls this "IMAGE" or "I" mode)
In "ASCII mode", any form of data that is not plain text will be corrupted. When a file is sent using an ASCII-type transfer, the individual letters, numbers, and characters are sent using their ASCII character codes. The receiving machine saves these in a text file in the appropriate format (for example, a Unix machine saves it in a Unix format, a Windows machine saves it in a Windows format). Hence if an ASCII transfer is used it can be assumed plain text is sent, which is stored by the receiving computer in its own format. Translating between text formats might entail substituting the end of line and end of file characters used on the source platform with those on the destination platform, e.g. a Windows machine receiving a file from a Unix machine will replace the line feeds with carriage return-line feed pairs. It might also involve translating characters; for example, when transferring from an IBM mainframe to a system using ASCII, EBCDIC characters used on the mainframe will be translated to their ASCII equivalents, and when transferring from the system using ASCII to the mainframe, ASCII characters will be translated to their EBCDIC equivalents.
By default, most FTP clients use ASCII mode. Some clients try to determine the required transfer-mode by inspecting the file's name or contents, or by determining whether the server is running an operating system with the same text file format.