19

I understand the difference between ASCII mode vs binary when it comes to FTP, but what I don't understand is why there is even a need for ASCII mode at all? Is this just a legacy thing that used to save time by eliminating the most significant bit, therefore causing the overall speed of the transfer to increase by 1/8th? Or is there some hidden use for it that I don't know about?

I've encountered many problems because I would forget to switch the mode to bin when transferring text between different OS's. I don't understand why "bin" isn't just the default for everything, especially with today's much faster internet speeds.

Knowwutimean, Vern?

MALON
  • 722
  • 1
  • 8
  • 22
  • This is probably offtopic for SO. But, ASCII mode is for transferring text, and even today different systems have different ways of representing text - FTP provides a lowest comon denominator mechanisms to translate between these systems - otherwise you might end up transferring a file that's text on the remote system which ends up being garbage on your system. And keep in mind, FTP is not just used between modern OSs, it's used to fetch stuff of 30 year old stuff too. – Lyke May 27 '11 at 18:15

4 Answers4

14

ASCII mode exists so you can get the right answer when you upload a text file to a remote system without having to know what the line termination or character set conventions are for that system. It was more important when transferring text files was more often done via FTP than, say, email.

To address your practical problem: check the documentation for both your FTP client and server(s) to see if there's a way to set ASCII mode by default. Often this is as simple as some kind of "profile" that sends some FTP commands every time you connect.

To address your philosophical problem: FTP is a 40 year old protocol that has its fair share of historical baggage. One day you'll be very glad that some protocol you depend on was standardized long ago and you can still access some old data.

Perry
  • 1,152
  • 10
  • 14
5

I, for one, vote to eliminate ascii mode from ftp servers. Any EOL translation can be done by applications consuming the files, and many apps today understand both EOL types anyway. At a minimum, I'd like to see servers switch to using binary by default, and only use ascii if requested.

Brady Moritz
  • 8,624
  • 8
  • 66
  • 100
  • There's more than just the two EOL types implied by your "both" comment: CR/LF on Windows, LF on Unix, and CR on Macintosh. And who knows what else. But I'm with you: the possible loss of the high bit, or other unintentional conversions, introduced by use of ASCII mode makes it completely useless IMO. – ALEXintlsos Nov 08 '13 at 20:57
  • my text editors on my winadows machine work equally well with both styles of EOL... some will ask if I want to convert from unix to windows style. This is all fine for apps to do, but terrible for a file transfer protocol to try to figure out. – Brady Moritz Nov 12 '13 at 13:58
  • 1
    @ALEXintlsos "Both" because Mac switched to LF (like UNIX) as of Mac OS X 10.0 in 2001. – Damian Yerrick Dec 15 '17 at 18:48
1

One scenario of practical use of ASCII mode is to upload PHP or Perl or similar scripts from Windows development machine to Unix server. Use of Binary mode would require separate conversion of line ending sequences, while with ASCII mode conversion is performed "automatically".

Update: there's one more scenario that we have come across - when transferring data to/from mainframes that use EBCDIC encoding, ASCII mode tells the server to perform conversion between encodings.

Eugene Mayevski 'Callback
  • 45,135
  • 8
  • 71
  • 121
0

Here's a practical example of a problem that comes from using a binary FTP connection. In php there are two types of comments:

// a single line comment like this
/* a block comment like this */

The block comment has a start and an end. But the single line comment just ends at the end of the line.

If you upload a php file with single line comments using a binary connection, the php will stop running as soon as it hits the single line comment. It doesn't recognise the end of the line as the end of the comment, so it effectively comments out the rest of your php script.

If however you use FTP in ASCII mode, it will correctly read the end of the line and will run your php code as expected.

Josh Moore
  • 176
  • 1
  • 5
  • 1
    Are you sure you don't have binary and ASCII switched? According to other questions it seems ASCII was the cause for removing line breaks and binary was the fix: http://stackoverflow.com/questions/4547516/filezilla-removes-line-breaks-on-php-files# – Tyler Mar 18 '16 at 03:34
  • Interesting ... my experience was the opposite of that page you linked. When we forced it to be ASCII then the comments worked, but I might need to go back and check in case I've got it the wrong way around. – Josh Moore Mar 21 '16 at 02:24