FTP ----ASCII or Binary (zt)

上一篇 / 下一篇  2007-12-20 00:00:00 / 个人分类:Others

Uploading and downloading files in the proper mode is important. Find out why it matters, and which should be transferred as ascii & which as binary.

Ascii or Binary?

The general rule of thumb is if you can view the file in a text editor like notepad (ie. .html, .js, .css files etc) you should upload in ASCII mode, most others (including images, sound files, video, zip files, executable's etc) should be uploaded in Binary.


$Aq%rf L0

Exceptions to the Rule

It seems all things related to computers have exceptions to the rules. Yes, this is yet another case of it.

If your text files contain international characters (ie. Chinese or Japanese text), they are to be uploaded as binary. The reason is that ascii takes into account differences between DOS and UNIX files (7 bits) but it doesn't do well with text using higher bits.

Why Does It Matter What Mode You Transfer Files With?

If you upload images etc. as ascii you'll end up with corrupted files. Some browsers seem capable of figuring it out, but not all... and not all the time. Netscape is much more picky, so you'd end up with broken or missing pictures for your Netscape users. (Yup, I learned this the hard way :-o )

Same thing with uploading text files as binary. While this is less important for html files, scripts will have a HUGE problem with it and will just not work. This is the most common cause of the "Server 500 Error - Malformed Headers", and other equally unlovely errors that have caused many a webmaster to bang their heads against their computers.

So What Does Uploading In ASCII Do?

I'd wondered this for a while and finally decided to learn why uploading in ascii is so important for some file types. What I found out is that different Operating System's use different ways to specify that a line has ended. So if you're using a different operating system than your server (which is very likely), the files will have extra characters at the end of each line that the server doesn't recognize. So it'll usually print them out resulting in script errors.

Setting Your FTP Program to "Auto"

Most FTP programs have the option to set your upload to auto. What this usually does is compare the file type you're transferring against a list of known file types and set it to binary or ascii upload on its own.

By default, most FTP programs will have a pre-set list of files to be transferred in ascii and will upload / download everything else in binary. (These settings are in different places depending on the program you are using. Check the "Read Me" file or their Website if you can't find it.) Be sure to double check that the files you want to transfer are in the appropriate list.

Summary

ASCII FilesITPUB个人空间1u\ U9k9W s-G
.htm .html .shtml .php .pl .cgi .js .cnf .css ITPUB个人空间7Hj-K"gv3u
.forward .htaccess .map .pwd .txt .grp .ctl

Binary Files
/s$x ])Db%Lp J7h0.jpg .gif .png .tif .exe .zip .sit .rar .ace ITPUB个人空间p.l} d1d g#S0c
.class .mid .ra .avi .ocx .wav .mp3 .au

FTP可用多种格式传输文件,通常由系统决定,大多数系统(包括UNIX系统)只有两种模式:文本模式和二进制模式。文本传输器使用ASCII字符,并由回车键和换行符分开,而二进制不用转换或格式化就可传字符,二进制模式比文本模式更快,并且可以传输所有ASCII值,所以系统管理员一般将FTP设置成二进制模式。
C*ni-_fo;tz&K0ITPUB个人空间V#D f1{Hy5v(@
一般来说:
\.Bi#I%F7]Ck V R0如果你用错误的模式传输你的图片,你将会无法看到图片,看到的会是乱码。 ITPUB个人空间8C oCI/nl:z
如果你用错误模式上传CGI脚本,那么就将无法运行你的脚本,会看到类似Server 500 Error的出错信息。 ITPUB个人空间$OFsG\r6a
所以你必须使用正确的模式,图片和执行文件必须用BINARY模式,CGI脚本和普通HTML文件用ASCII模式上传.
6A4M*E|b`U&n0
7u*`+HA8l"~ Tr `c0ASCII和BINARY模式区别: ITPUB个人空间)n i x:r#p7[X
用HTML 和文本编写的文件必须用ASCII模式上传,用BINARY模式上传会破坏文件,导致文件执行出错。
9X,gmR0j0
ODj!`:C5[-lk6p0BINARY模式用来传送可执行文件,压缩文件,和图片文件。
8Yme_Y"y"{IKQ;l0如果你用ASCII模式传,会显示一堆乱码,你必须重新用BINARY模式传。 ITPUB个人空间:^p7n!uOb7H

S7M{ j3^0对于第二种情况,是因为有很多ftp服务器和客户端软件能自动识别文件类型,并采取相应的传输方式。 ITPUB个人空间:q;SI)fN-c(nx;Tk
ITPUB个人空间n.F;aclr
ftp是应用层协议,和具体操作系统无关 .
!C2a1G1WY:P&n$i7w0ITPUB个人空间1~!d{!dT/[ N

'L:`4bk7{0ASCII模式和BINARY模式的区别是回车换行的处理,binary模式不对数据进行任何处理,asci模式将回车换行转换为本机的回车字符,比如Unix下是n,Windows下是rn,Mac下是r
}3q.q.G,S!?~e`0
(X!FG HU"I:{u A0ascii模式下会转换文件
NA{-f6[j M0不能说是不同系统对回车换行解释不同 ITPUB个人空间EUI"qn"{c
而是不同的系统有不同的行结束符 ITPUB个人空间k5s_H7MUH
unix系统下行结束符是一个字节,即十六进制的0A
-ETf8`g0而ms的系统是两个字节,即十六进制的0D0A ITPUB个人空间-R;H7C cR h[9I5Kp6c+S7i
所以当你用ascii方式从unix的ftp server下载文件时(不管是二进制或者文本文件),每检测到一个ITPUB个人空间^%HHBt4s-F

O&W/N-I(FJ0字节是0A,就会自动插入一个0D,所以如果你的文件是二进制文件比如可执行文件、压缩包什么的,就肯
#]+ivLg(R&C0
i6s;X:m MO)~2SJ0定不能用了。如果你的文件就是unix下的文本文件,你用ascii模式是正确的,要是误用了binary模式,
"Ac~Y9q0ITPUB个人空间Q2N/oR`4ep
你在windows上看这个文件是没有换行的,里面是一个个的黑方块。 ITPUB个人空间9ZA y5f2t2|e
一般来说,我们最好都用binary方式,这样可以保证不出错。如果有文本格式转换的问题,即unix格式
5ESYe+H/D0ITPUB个人空间#C:e$A|&{B
的文本和dos格式的文本之间的转换,有很多工具可以做的,不要在ftp传输的时候冒险,尤其是你如果对
&Wl.Bp"tr9?(q0
[/OV Mp-?q0这些东西不是非常清楚的话。ITPUB个人空间t{*MA+Q
ITPUB个人空间NS5`C._2\
可以使用MIME,把所有的字符,转换成0~128之间的字符,然后传送,在接受方再将接收到的字符MIME反向转换。通常我们发送邮件,就是使用这样的字符转换方式。

from : http://shikary.blog.sohu.com/53940630.html


TAG:

杂记铺 引用 删除 fjmingyang   /   2008-07-31 16:57:29
雷达数据?  兄弟,人才
引用 删除 elf   /   2008-05-21 12:13:46
最近在弄这些东西,五六百G的ASCII雷达数据,全都要转换成binary,我晕了,弄了好多天了,幸好给我弄了个DELL品牌,双核+2G memory.
 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

日历

« 2008-12-05  
 123456
78910111213
14151617181920
21222324252627
28293031   

数据统计

  • 访问量: 6960
  • 日志数: 481
  • 图片数: 3
  • 文件数: 1
  • 建立时间: 2008-01-05
  • 更新时间: 2008-11-20

RSS订阅

Open Toolbar