I tried fetching/putting a windows-style text file (between a solaris server and my local linux box) using ascii mode with both Net::FTP and the command-line ftp utility. They both preserved the "\r\n" line terminations in the text file.

I noticed that the alleged "ascii" mode transfer actually causes more bytes to be transmitted -- a remote file with 20162 bytes (including 278 \r's and 279 \n's) reports 20441 bytes sent, whereas a binary transfer reports exactly 20162 bytes. Alas, both methods leave me with a 20162-byte file (i.e. no difference in the local copy). Anyway, it might not be the fault of the perl module.

This is the expected behavior. The sending system in an FTP ASCII transfer takes whatever the local notion of a line is and sends it as a series of characters terminated with CR-LF "\r\n". So if you are sending from a Unix system, a file that starts of "abc\ndef\r\nghi\n" will be sent as "abc\r\ndef\r\r\nghi\r\n". Any \r that is already in the text file is treated as just another character.

The receiving system in an FTP ASCII transfer translates the CR-LF pairs back to whatever the local notion of a line is. So on another Unix system, you'll get back the original file.

On Windows, though, it's different. A file that starts "abc\r\ndef\r\n" will be sent just like that in ASCII mode. A receiving Unix FTP process (in ASCII mode) will convert it to "abc\ndef\n".

As I said above, if he is running Cygwin Perl instead of ActivePerl, and the file is on a binmode mount, then the file will be treated just like a Unix file.


In reply to Re: Re: NET::FTP ASCII mode not translating end-of-lines by Thelonius
in thread NET::FTP ASCII mode not translating end-of-lines by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.