LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (http://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Problem with FTP ascii transfer (http://www.linuxquestions.org/questions/linux-networking-3/problem-with-ftp-ascii-transfer-755160/)

clvic 09-14-2009 03:17 PM

Problem with FTP ascii transfer
 
Hi everyone,
I had a problem with the old good ascii/binary FTP transfer modes.
I transferred some files (SQL scripting files, in which carriage returns DO matter) using FTP from a windows system to a linux system using filezilla "auto" mode, that should have resulted in ASCII mode for my sql files. These files are well formed and identical to the originals.
Then, someone else picked these files and moved them to another ftp server.
I finally found that all <CR><LF> couples have been transformed in <CR><CR><LF>.

I guessed that the problem was in the ASCII transfer mode - but, how comes that <CR><LF> => <CR><CR><LF>? I would have rather expected <CR><LF> to become <CR>.

I hope I've been clear, thanks to everyone that will answer!

anomie 09-14-2009 04:01 PM

That sounds odd. A slight tangent, but an alternative is to simply transfer the files in binary mode only -- and then use dos2unix / unix2dos to do the conversion for you.

lutusp 09-14-2009 07:11 PM

Quote:

Originally Posted by clvic (Post 3682640)
Hi everyone,
I had a problem with the old good ascii/binary FTP transfer modes.
I transferred some files (SQL scripting files, in which carriage returns DO matter) using FTP from a windows system to a linux system using filezilla "auto" mode, that should have resulted in ASCII mode for my sql files. These files are well formed and identical to the originals.
Then, someone else picked these files and moved them to another ftp server.
I finally found that all <CR><LF> couples have been transformed in <CR><CR><LF>.

I guessed that the problem was in the ASCII transfer mode - but, how comes that <CR><LF> => <CR><CR><LF>? I would have rather expected <CR><LF> to become <CR>.

I hope I've been clear, thanks to everyone that will answer!

It is easier to solve a problem like this than to try to diagnose it. Write a script that finds line endings (of any kind) and converts them to your preferred line ending. Regardless of the script language, the essential regex looks like this:

/(\r|\n)+/\n/

BUT ... before using this method, make sure there are no intentionally blank lines (e.g. multiple line endings with no intervening text) such as one finds in plain-text documents. For that case, you really do need to specify the exact line ending you are looking for:

/\r\r\n/\n/

Again, this is an example where a cure is much easier than a diagnosis.

Quote:

I would have rather expected <CR><LF> to become <CR>.
Only on a Macintosh:

Macintosh: \r
Windows: \r\n
Linux/most Unices: \n


All times are GMT -5. The time now is 03:17 AM.