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%LpJ7h0.jpg .gif .png .tif .exe .zip .sit .rar .ace ITPUB个人空间p.l} d1dg#S0c
.class .mid .ra .avi .ocx .wav .mp3 .au
FTP可用多种格式传输文件,通常由系统决定,大多数系统(包括UNIX系统)只有两种模式:文本模式和二进制模式。文本传输器使用ASCII字符,并由回车键和换行符分开,而二进制不用转换或格式化就可传字符,二进制模式比文本模式更快,并且可以传输所有ASCII值,所以系统管理员一般将FTP设置成二进制模式。
C*ni-_fo;tz&K0ITPUB个人空间V#Df1{Hy5v(@
一般来说:
\.B i#I%F7]CkV
R0如果你用错误的模式传输你的图片,你将会无法看到图片,看到的会是乱码。 ITPUB个人空间8CoCI/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,g mR0j0
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