Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Using the following script, I upload gifs on my ftp server. The scripts seems to work, but when I tried to access the image in my browser they are broken. Any idea why ?


ftp -n $HOST <<END_SCRIPT                   
quote USER $USER                            
quote PASS $1                               
put $2                                      
exit 0     
share|improve this question
maybe you should switch ftp over to binary mode just in case its trying to upload your files in text mode? – radai Feb 13 '13 at 20:30
up vote 12 down vote accepted

Your images get uploaded in network ASCII mode rather that binary mode.

Network ASCII mode is useful when transferring text files (plain text, HTML, etc.). If you transfer, e.g., a text file from a client running Windows to a server running Linux, it will automatically convert all Windows line breaks (13 10) into Unix line breaks (10) and add a trailing end-of-file character (10).

Evidently, this causes file corruption when transferring binary files such as images.

To switch to binary mode, execute this command before put:


From man ftp:

ascii    Set the file transfer type to network ASCII.
         This is the default type.

binary   Set the file transfer type to support binary image transfer.
share|improve this answer
"Evidently, this causes file corruption when ...". Aye, because every occurence of (13 10) will be translated. Even when they are not part of a text end-of-line. – Hennes Feb 13 '13 at 20:56
Does anyone else remember uncook? Web servers didn't know about mp3 files then, so they served mp3s as txt, and the Windows clients would bork files like this. Uncook unborked them. – Rich Homolka Feb 13 '13 at 21:11
Well thank you, using binary solved it. – Matthieu Riegler Feb 13 '13 at 23:58
No, ASCII mode is not useful, infact it's one of the most evil hacks of the entire software history. Any editor worth its name will accept any of the possible line endings -.- But even if this wasn't the case, it's not FTP's responsibility to fix the file format. If I use FTP to transfer a movie and I don't have the codec on the target pc, it doesn't re-encode it, so why mess with text files – Andreas Bonini Feb 14 '13 at 0:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .