2

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 ?

#!/bin/sh                                   
HOST='myftp'                       
USER='mylogin'                              

ftp -n $HOST <<END_SCRIPT                   
quote USER $USER                            
quote PASS $1                               
put $2                                      
quit                                        
END_SCRIPT                                  
exit 0     
1
  • 4
    maybe you should switch ftp over to binary mode just in case its trying to upload your files in text mode?
    – radai
    Feb 13, 2013 at 20:30

1 Answer 1

12

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:

binary

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.
3
  • "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, 2013 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. Feb 13, 2013 at 21:11
  • 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 Feb 14, 2013 at 0:48

You must log in to answer this question.

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