Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

why ^M are added while iam transfering file using binary in Net::FTP

by shanthiann (Acolyte)
on Sep 12, 2006 at 13:15 UTC ( [id://572523]=perlquestion: print w/replies, xml ) Need Help??

shanthiann has asked for the wisdom of the Perl Monks concerning the following question:

hi perl
iam using Net::Ftp , if iam transfering files from windows to linux using ascii is not adding ^M charters .
if iam using binary it is adding .
If i see that same file in windows it is showing properly.
Can any body explain why this is happening
  • Comment on why ^M are added while iam transfering file using binary in Net::FTP

Replies are listed 'Best First'.
Re: Why ^M are added while I am transfering file using binary in Net::FTP
by davorg (Chancellor) on Sep 12, 2006 at 13:24 UTC

    Because line endings are different on Unix (and Linux) and DOS (and Windows). And they don't get translated in binary transfer mode.

    See my article Why Does My File Have Funny Characters In It? for more details.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Re: why ^M are added while iam transfering file using binary in Net::FTP
by gellyfish (Monsignor) on Sep 12, 2006 at 13:24 UTC

    No you have it the wrong way round. When you do an FTP transfer in ASCII mode it alters the line endings as appropriate, when in binary mode it doesn't. The ^M you are seeing is part of the Windows line-ending that is not understodd by systems that have Unix line-endings. The Windows line-ending is two characters, whereas the Unix line-ending is one.

    /J\

Re: why ^M are added while iam transfering file using binary in Net::FTP
by sen (Hermit) on Sep 12, 2006 at 13:48 UTC

    Follow this link, it will be useful

    dos2unix

Re: why ^M are added while iam transfering file using binary in Net::FTP
by planetscape (Chancellor) on Sep 12, 2006 at 21:24 UTC
Re: why ^M are added while iam transfering file using binary in Net::FTP
by DentArthurDent (Monk) on Sep 12, 2006 at 18:30 UTC
    Here's how it should work as I understand it:

    For ASCII mode, your line endings will be translated if possible. From UNIX to Windows, ^M (carriage return) characters are added. From Windows to UNIX they are removed, I believe. For binary mode, none of that translation is done.

    So for true text files, often you really want to use ascii mode. However, for just about anything else, you really want binary. You can really pull you hair out if you transfer a linux executable through a windows box back to linux if you use ASCII in one of the transfers.

    Bottom line: Think carefully, and be consistent!

    ----
    My mission: To boldy split infinitives that have never been split before!
Re: why ^M are added while iam transfering file using binary in Net::FTP
by runrig (Abbot) on Sep 12, 2006 at 18:36 UTC
    if iam using binary it is adding .
    No, it is not adding them, it is leaving them in. In ascii mode, it removes them.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://572523]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (7)
As of 2024-04-23 19:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found