Chinaunix首页 | 论坛 | 博客
  • 博客访问: 856320
  • 博文数量: 254
  • 博客积分: 5350
  • 博客等级: 大校
  • 技术积分: 2045
  • 用 户 组: 普通用户
  • 注册时间: 2008-06-27 13:27
文章分类

全部博文(254)

文章存档

2015年(1)

2014年(9)

2013年(17)

2012年(30)

2011年(150)

2010年(17)

2009年(28)

2008年(2)

分类: 系统运维

2011-03-29 14:43:08

   
What is ASCII?

ASCII: the American Standard Code for Information Interchange. It's the code by which computers have stored and exchanged text for the last 40 or more years.

ASCII has been the mainstay of information interchange for four decades, but it has limitations. Designed during a time when computer memory (RAM) was very expensive, it used only the low 7 of the 8 bits in a standard byte. This was adequate, and allowed the leftover bit to be used (occasionally) for other purposes.

What is Binary?

Binary is the number system based on 2. In this context, though, it refers to numeric, as opposed to text, information. While ASCII text uses only 7 of the 8 bits in a byte, numbers use all 8.

Not only do numbers themselves use all 8 bits, but so do most other types of computerized information (all of which use numbers to represent information), including:

  • programs
  • images
  • databases
  • music
  • video
  • word processing documents
  • compressed files

It comes as a surprise to many people that word processing documents, such as Microsoft Word and Word Perfect files, are binary rather than ASCII. That's because they store a great deal of information besides just the letters: they contain font and formatting information, images, user preferences, and many other "bells and whistles".

ASCII and Binary in FTP

Why Does FTP Have Both?

FTP was developed at a time when typical modem speeds were 110 to 300 bits per second (as compared with 28,000 to 56,000 today). Since ASCII only used 7 bits, long files could be transmitted more quickly by not sending all the unused bits.

The big drawback is that if a file that uses all 8 bits in each byte is accidentally sent using ASCII transfer, it will lose 1/8 of its information content. In most files, even the loss of one bit is enough to make it invalid, and losing 1/8 makes them totally unreadable. So ASCII transfer can be fatal to a file's health!

With today's higher speeds, the time lost by sending all 8 bits of an ASCII file is practically unnoticeable. But FPT has incorporated features into ASCII transfer that make it useful for other reasons, so the two modes remain.

The fact that they both remain means that FTP users need to exercise great caution in transferring files!

What Extra Services Does ASCII Transfer Have?

What features are so useful that FTP retains ASCII transfer in spite of the risk of ruining files in transmission? There are two: end-of-line translation, and end-of-file translation.

Although ASCII has standardized almost all aspects of text files shared between computers, there are two areas where operating systems have "agreed to disagree". One is how you symbolize the end of a line, the other is how you mark the end of a file.

When files are transferred using ASCII mode, FTP clients and servers will translate the different symbols into the native "language" of the receiving computer. This eliminates files that appear to have "garbage" in them, or that appear to be all one long line stretching from here to the horizon. There are some programs used in making the Web interactive, that depend on having the right line-break characters.

In case you're interested or need to know the details, here they are:

  ASCII character numbers
followed by
[Character Names]
System End-of-Line End-of-File
IBM, DOS, Windows, VAX-VMS 13+10
[CR]+[LF]
26
[^Z]
Linux, Unix 10
[LF]
04
[^D]
Macintosh OS 1-9 13
[CR]
04
[^D]
Macintosh OS X Flexible: either
[LF] or [CR]
04
[^D]

 

How to Set Transfer Mode

Setting Transfer Mode in Character-Based FTP Clients

If you use a command-line FTP client: The default mode is ASCII. Every time you intend to transfer a binary file, you need to type the command,
binary
before typing in the get or put command.

FTP will stay in binary mode until you change it, so if you then transfer ASCII files, you need to type the command
ascii
before typing the get or put command.

How To Set Transfer Mode in a GUI-based FTP Client

GUI-based FTP clients are each different, but since we use WS-FTP at WCC, we'll focus on that.

WS-FTP has three controls for mode: ASCII , Binary , and Auto . Auto is a check box, and does not affect the status of the other two, while ASCII and Binary are "radio buttons", meaning you have to choose one or the other. Here's how they work:

  • If Auto is OFF (unchecked), and:
    • ASCII is ON : All transfers will be in ASCII mode.
    • Binary is ON : All transfers will be in binary mode.
  • If Automatic is ON (checked), files are transferred in binary mode unless the extension is listed in a table set up in WS-FTP. Details follow...
"Automatic" Mode

The behavior of WS-FTP in Auto mode depends on a list of file extensions it keeps.You can access that list by clicking the Options button at the bottom of the WS-FTP LE window (or the top of the WS-FTP Pro window).

In the Options dialog, click the Extensions button. This brings you to the list of extensions. The illustration at left shows the default list of ASCII extensions - only .TXT. (This is not case-sensitive.)

If you're transferring Web files, HTML files could also be in this list.In addition, there are a number of other file type used on the Web that are text files and should be transferred using ASCII mode. These are listed in the table in the next section.

Summary: Practical Advice

WS-FTP Help offers this advice:
  • A file that is text, HTML, postscript, other ASCII format (.txt, .html, .htm, .cgi), or EBCDIC should be transferred in ASCII mode. Note: Transferring a binary file in ASCII format can damage the file.
  • A file that is a bitmap, an executable, or compressed (.bmp, .jpg, .exe, .zip) should be transferred in binary mode. (Binary mode should also be used if there is no file extension or the file extension is not registered.)

Here's a quick overview of files and how they should be transferred:

ASCII Binary
.txt ASCII text .txt Unicode text - see below
.htm
.html
HTML
Web page
.jpg
.jpeg
JPEG image
.xml Extensible Markup Language .gif CompuServe GIF image
.cgi Common Gateway Interface script .png Portable Network Graphics
.pl Perl scrips must be transferred in ASCII .bmp Windows bitmap image
.php PHP program script .doc MS Word or Word Perfect document
.cf Cold Fusion script .xls MS Excel spreadsheet
.svg Scalable Vector Graphics image .mdb Microsoft database file
.asp MS Active Server Pages script .exe
.com
.dll
Executable programs
.rtf Rich Text Format .zip Compressed files
.ps Postscript files .pdf Adobe Acrobat Portable Document Format files

  使用bin命令传输时,什么也不会改变,按照源文件传输,关于FTP传输模式ACSII mode和 BIN mode
2010年01月04日 星期一 11:31 A.M.

一般来说:
如果你用错误的模式传输你的图片,你将会无法看到图片,看到的会是乱码。

如果你用错误模式上传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\nMac下是\r
ASCII
模式下会转换文件,不能说是不同系统对回车换行解释不同,而是不同的系统有不同的行结束符。UNIX系统下行结束符是一个字节,即十六进制的0A,而 Windows的系统是两个字节,即十六进制的0D0A,所以当你用ASCII方式从UNIXFTP Server下载文件到Windows系统上时(不管是二进制或者文本文件),每检测到一个字节是0A,就会自动插入一个0D,所以如果你的文件是二进制 文件,比如可执行文件、压缩包什么的,就肯定不能用了。如果你的文件就是UNIX下的文本文件,你用ASCII模式是正确的,要是误用了Binary模 式,你在Windows上看这个文件是没有换行的,里面是一个个的黑方块。一般来说,我们最好都用Binary方式,这样可以保证不出错。如果有文本格式转换的问题,即UNIX格式的文本和DOS格式的文本之间的转换,有很多工具可以做的,不要在ftp传输的时候冒险,尤其是你如果对这些东西不是非常清楚的话。如何设置FTP的传输方式呢?
ftp>提示符下输入ascii即转换到ACSII方式,输入bin,即转换到Binary方式.

使用bin命令传输时,什么也不会改变,按照源文件传输,
而用ascii方式传输时会将行结束符从来源的机器所用的行结束符转换成接收机器所用的行结束符。
阅读(901) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~