Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm transferring files between servers and just started noticing that some of them are getting modified to be one long continuous line as opposed to having the returns and line-breaks they originally had. I'm assuming this has something to do with the transfer-type of my FTP Client which was originally set to "Auto," but sporting "Binary" and "ASCII" as additional options.

In short, what are the differences between the ways I transfer a file from one server to another, and will these differences be capable of modifying the file in such a way as I mentioned above?

Transfering FROM Windows TO Linux.

share|improve this question
add comment

4 Answers 4

up vote 13 down vote accepted

The "Binary" transfer mode of FTP copies files exactly, byte for byte. Simple and straightforward.

When bringing text files between different operating systems, though, this might not be what you want -- different operating systems use different codes to represent line breaks. The "ASCII" mode exists for this purpose: it automatically translates all line endings from the source system's format to the destination's.

Not sure about "Auto", but I imagine it looks that the file's extension or something similar to decide whether it's a text file, and tries to guess the appropriate mode.

Which mode you want depends on exactly what you're doing with the files... if you're just copying them to back them up, then you'll probably want to copy in binary mode so they'll be exactly the same when you later restore them to the windows server again. If they need to be usable as text files (perhaps as config files for a cross-platform program?) on both sides, you'll want to use ASCII mode to translate them.

EDIT: As far as I can tell, FTPing files from Windows to Linux should never result in line breaks disappearing... however, if you copy them in ASCII mode, and then bring them back to the Windows server in binary mode, the Linux-style line endings might not be recognized on the Windows box. (Notepad won't see them; Wordpad will; YMMV with other software.)

(Today, such a convenience -- converting line endings automatically -- might seem odd in such a basic protocol as FTP. When FTP was invented, though, sending text files was the norm, and one of the goals of the protocol was to make this as easy as possible.)

share|improve this answer
    
Great description of both. I feel a lot less confused now. –  Jonathan Sampson Feb 9 '10 at 15:35
    
thank you I never understadnd the point of that ASCII mode, and now I will definitely only use binary mode –  Kiwy Feb 5 at 9:43
add comment

There are differences indeed, and they will be messing with your non-plain-text file transfers unless you use the binary option - generally always use if ok :)

share|improve this answer
    
Is there no way to restore them? Or do I simply need to transfer with Binary now to avoid this again in the future? –  Jonathan Sampson Feb 8 '10 at 16:14
    
I'm sure you could unpick them but it might take a long time, I'd be strongly tempted to retransmit them. –  Chopper3 Feb 8 '10 at 16:18
add comment

What operating system are you transferring files to/from? Linux/Unix use different line breaks then Windows. So if you generate a file on a linux computer and open it on windows it may look weird. There are utilities to correct this though in my experience if you use wordpad on windows instead of notepad you'll be fine.

share|improve this answer
    
I'm authoring these on windows in an IDE, and then moving them to the linux server. At a later date, I open them from the linux server to find the long continuous line. –  Jonathan Sampson Feb 8 '10 at 16:16
    
Try running dos2unix and see if that corrects the lines –  einstiien Feb 8 '10 at 16:58
add comment

Windows and Unix have different bytes at the end of lines (Windows a 0D 0A hex, Unix just a 0A). When transferring files in Binary mode, the bytes of a file will be moved from one computer unchanged. This is required for binary formats (e.g. ZIP files, Images, etc.) but can lead to problems with text files: E.g. notepad.exe on Windows will display a text file with just unix style line breaks as one long line, a unix editor might show ^M at the end of every line when seeing Windows style.

So technically for binary formats (zip, jpg, png, and endless others) you need to set the FTP to BINARY, while for text formats (HTML, PHP, CGI, etc.) you need to set it to ASCII.

Most good FTP programs also have an auto setting, which means they will determine the mode (BINARY or ASCII) depending on well known file extensions, e.g. it will automatically switch the transfer for JPG file to BINARY and send/receive a PHP file in ASCII mode.

share|improve this answer
add comment

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.