Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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     
share|improve this question
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 '13 at 20:30

1 Answer 1

up vote 10 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:

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.
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.