FTP ACSII mode和 BIN mode

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.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值