FTP and the Difference Between ASCII and Binary Modes

Edit: Thanks to Brian Layman for picking up some horrible errors on my part on the below 🙂

A slightly more technical article for today.

For those of you who use FTP every now and then along with FTP client software such as FileZilla or the command line FTP utility that comes with Windows you may have noticed that there are two file transfer methods, ASCII and binary. What you may not realise is the difference between these transmission types especially if the client software makes that determination for you.

To break things down a bit, ASCII stands for American Standard Code for Information Interchange which was used to define how text is represented in computers. ASCII included a mix of printable characters (such as letters, numbers and various symbols) and control characters that controlled how text and space was interpreted. When text was to be stored or transferred between computers it was done in ASCII format.

Conversely, the term “binary file” is a fancy name for a file that contains executable code (i.e. it is an application or part of an application such as a DLL file). If you happened to open one of these up in a text editor you would see all sorts of noise such as the example below.

Notepad Binary Code

Notepad Binary Code

So what is the difference between ASCII and binary modes in FTP?

Basically, ASCII mode is used for non-executable plain text files (so documents, spreadsheets, pictures, batch/shell scripts, HTML files, JavaScript files, etc) as this mode handles the conversion of the various characters in the file based upon the operating system being used on the receiving client (particularly if it differs from the operating system of the sending computer). This is particularly important for hidden end of line characters and other control characters as they differ in usage across platforms.

Conversely, binary mode eliminates this conversion and enacts a strict and exact byte for byte transfer between the two computers. This means the file will be structurally identical on both machines. This is important for files such as pictures, music and videos which must be exact copies in order to preserve the integrity of the data.

Executable files should also be transferred in binary mode however this does not mean that the binary file can run on the recipient computer if it is running a different operating system (unless it was written in something Java or another higher level language that runs on top of platform specific language interpreters). It’s also important that ZIP files should be treated as binary files so as to not break the compression dictionary or digital signature on the file. If you use FTP as a means to backup your data in ZIP files to a remote server then this will be particularly important if you’re scripting the transfer from scratch – definitely something to verify when testing your scripts.

It’s also worth noting that FTP client software tends to treat files as ASCII binary by default unless told otherwise (either by built in settings or by an explicit switch that is specific upon transmission).

FileZilla - ASCII Transfer File Types

FileZilla – ASCII Transfer File Types

Windows FTP Command Line

Windows FTP Command Line

So now you should know the difference between ASCII and binary FTP modes and how the selection of these modes can be influenced by the FTP client software.

5 comments

Skip to comment form

  1. This is close, but there’s one issue here. The difference between files needing binary or ascii transfer is not that the file is executable or not. The simplest way to say it is that if a file can be read in notepad or any other plain text editor, it can be sent in ascii.

    Your statement that ascii covers “documents, spreadsheets, pictures, scripts, etc” is incorrect. Documents, spreadsheets, pictures are all binary files. Word will not be able to load a .doc file any more if it is sent in ascii. Same for a JPEG picture or an Excel XLS file..

    ASCII transfers say “Hey computer on the other side, I’m sending you some words. If you need to translate them into your own language in order to understand them, go ahead and do it.” Binary transfer says – here’s a file and it just better be EXACTLY the same when it gets there.”

    An ASCII transfer was useful when computers/servers used different storage methods for text files and when we were stuck using 1200bps modems. Today, it would be perfectly fine in just about any situation to send all files via binary.

    1. Hi Brian, thanks for picking up those horrible errors on my part! I’ve made the necessary corrections to the article.

    • Anusha on June 27, 2013 at 09:28
    • Reply

    Hi,
    Will the .dat file, can be converted to notepad or word format. In the .dat file, the text will be saved in binary language.. Will it be possible to convert it to plain text.

    1. If I am understanding your question correctly the answer is that you can’t use FTP to convert DAT files into a plain text file. If the DAT file is something like an Oracle database backup then using FTP won’t turn it into a plain text file.

    • THusitha Bandara on June 11, 2014 at 16:04
    • Reply

    One more issue I came across was that thought I upload the image file in binary, if I red the same in ascii, still the images get courrecpted. Once I chnaged to binary, things started working.

Leave a Reply

Your email address will not be published.