|
Overview
There are two ways of transferring files via FTP: ASCII and Binary. This article explains
the differences, and how to decide which one to use. (This has nothing to do with the
connection mode, which must always be set to Passive (PASV) at Spaceports.)
Making the wrong choice will cause problems more often than not, particularly in the case of
Perl CGI scripts and images.
Some FTP clients have an "auto" mode, but very few of them have settings for all file types by
default.
Binary Transfer Mode
In Binary mode a file is copied bit for bit from one machine to the other. Both files (the
original and the transferred file) will contain exactly the same sequence of bytes.
ASCII Transfer Mode
In ASCII mode a file may be changed slightly to maintain the meaning of EOL (End Of Line)
characters.
Okay, but why?
There are two common ways of ending a line in an ASCII text file. UNIX systems mark the
end of a line with a single character: a linefeed or newline (LF or NL). DOS (and Windows)
uses a pair a characters instead: a carriage return (CR) followed by a linefeed.
In order to preserve the meaning of these ends of lines when transfering files, the end of line
characters have to be changed. When going from UNIX to DOS, LF's have to be replaced with
CR/LF pairs. Similarly, when going from DOS to UNIX, CR/LF pairs have to be changed to a
single LF. That is the difference between them.
I believe that Macs use a single carriage return character.
In a UNIX text file, carriage returns are just like any other character (except that you can't
usually see them). If you transfer a text file from DOS to UNIX as a Binary file, it will
have carriage returns (which sometimes look like ^M or a rectangle) on the end of each line.
Choosing a mode
In general, Web pages and Perl scripts are ASCII text whilst images and programs are
Binary.
PHP programs will execute in either mode, but using ASCII mode is preferable as it is more
consistent with the document type (text), plus it saves one byte for every line in the document if
the original file is in Windows CR/LF format.
ASCII (text) files:-
Files named .cgi, .pl, .pm, .txt, .php, .shtml, .html and .htm
Binary files:-
.au, .aiff, .bin, .doc, .exe, .gif, .gz, .jpg, .jpeg, .mpg, .mpeg, .mov, .pdf, .png, .ps, .qt,
.tar, .tiff, .tif, .wav and .zip
|