Ftp – ASCII vs Binary vs Auto

asciibinaryfile-transferftp

I'm transferring files between servers and just started noticing that some of them are getting modified to be one long continuous line as opposed to having the returns and line-breaks they originally had. I'm assuming this has something to do with the transfer-type of my FTP Client which was originally set to "Auto," but sporting "Binary" and "ASCII" as additional options.

In short, what are the differences between the ways I transfer a file from one server to another, and will these differences be capable of modifying the file in such a way as I mentioned above?

Transfering FROM Windows TO Linux.

Best Answer

The "Binary" transfer mode of FTP copies files exactly, byte for byte. Simple and straightforward.

When bringing text files between different operating systems, though, this might not be what you want -- different operating systems use different codes to represent line breaks. The "ASCII" mode exists for this purpose: it automatically translates all line endings from the source system's format to the destination's.

Not sure about "Auto", but I imagine it looks that the file's extension or something similar to decide whether it's a text file, and tries to guess the appropriate mode.

Which mode you want depends on exactly what you're doing with the files... if you're just copying them to back them up, then you'll probably want to copy in binary mode so they'll be exactly the same when you later restore them to the windows server again. If they need to be usable as text files (perhaps as config files for a cross-platform program?) on both sides, you'll want to use ASCII mode to translate them.

EDIT: As far as I can tell, FTPing files from Windows to Linux should never result in line breaks disappearing... however, if you copy them in ASCII mode, and then bring them back to the Windows server in binary mode, the Linux-style line endings might not be recognized on the Windows box. (Notepad won't see them; Wordpad will; YMMV with other software.)

(Today, such a convenience -- converting line endings automatically -- might seem odd in such a basic protocol as FTP. When FTP was invented, though, sending text files was the norm, and one of the goals of the protocol was to make this as easy as possible.)