1.1. Before You Start: Understanding Transfer Modes

A complicating factor in transferring files from one computer to another is that you must decide whether the files you want to transfer should be treated as text of as binary. Files that contain simple text, including program source code, should be transferred in text mode. Compiled programs, compressed files (e.g., *.zip or *.Z files), and word processor files with embedded formatting codes are generally transferred in binary mode.

If you are uncertain about whether a file is text or binary, you can try looking at it. In Unix, do

less filename

In Windows, try loading the file into NotePad (not into Word or WordPad) or open a cmd window and give the command:

type filename

If you see "garbage" characters, you are dealing with a binary file. If the characters are all readable text characters formed more or less into recognizable words (remember that programming langauges can be pretty arcane) then you are dealing with a text file.

Now, you might think that the logical thing to do when trasnferring a file from one computer to another is to make sure that the file is, byte-for-byte, identical on both machines. And for binary files, that is exactly what we want. But, for text files the situation is not so simple.

The reason for this confusion is that Unix, MSDOS, IBM, and other systems disagree on how to represent basic text. For example, the end of a line in a Unix text file is represented by a single character (the ^J or line-feed character) while MSDOS uses a pair of characters at the end of each line (a^M or return character followed by a ^J). Other operating systems have their own peculiarities. Most file transfer programs will, when transferring text, try to convert the transferred file into the appropriate format for the destination machine. These conversions may involve changing, adding, or deleting characters. Of course, if the file being transferred were not text but a binary file, such as a compiled program, any such changes to individual bytes would be disastrous. Consequently, you need to be aware at all times whether the files you are working with are text or binary.

When in doubt, transfer in binary mode. If you do a transfer in binary mode and then discover that you have a text file with the wrong line terminators, you can correct that on the Unix side, as described in Section 1.5, “Problems and Inconsistencies”. On the other hand, if you transfer in text/ASCII mode and the file transferred is actually binary, there's no way to fix the damaged file.