Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

FTPing

by pikus (Hermit)
on Jul 11, 2004 at 15:48 UTC ( [id://373466]=perlquestion: print w/replies, xml ) Need Help??

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

Hello everyone! I am working on a CGI script for my website and things are moving along nicely. I have a book that is about Perl specifically and includes a few chapters on CGI. One of the more useful features of this book is a list of important things to remember, and on that list it says that when you're FTPing your CGI script you should send it in ASCII mode as opposed to binary. That's an easy enough thing to do, but I don't understand why. It seems to me that it's the same information either way, so why does it matter? I've been scouring the book for an explanation and if it's there I don't see it. Would one of you mind shedding some light on this for me? Thanks!
     - pikus
"I want to live 'till I die. No more. No less." - Eddie Izzard

Replies are listed 'Best First'.
Re: FTPing
by davido (Cardinal) on Jul 11, 2004 at 15:58 UTC

    This isn't actually a Perl question. It's a question about operating system differences, and how text is represented on different platforms.

    On some platforms text lines end in \012. In others, lines end in \015\012. And in others, lines end in \015. If you transfer files in "binary mode", line endings are not converted as you transfer across operating system platforms. If you transfer in text mode, line endings should be converted automatically.

    Perl scripts are text files, not binary files. So if you want your Perl scripts to be transferred with the proper line endings, you use text mode when transferring them. Or, as an alternative, you can transfer them in whatever mode you please and then use the "dos2unix" or the "unix2dos" utilities to convert the line endings after the fact.

    Again, this has nothing to do with Perl itself other than the fact that you can wreck a Perl script by failing to convert the line endings. In particular, people often notice that shebang lines stop working if the line endings aren't converted.


    Dave

      Thanks.
           - pikus
      "I want to live 'till I die. No more. No less." - Eddie Izzard
Re: FTPing
by Nkuvu (Priest) on Jul 11, 2004 at 15:52 UTC

    It is my understanding that it has to do with line endings in your script. If you send as binary, the line endings stay the same, no matter what the OS is on either end. This will, of course, cause problems when you FTP from something like Windows or Mac to Unix (or any other combination of differing OSs).

    If I recall correctly the ASCII mode automagically translates the line endings in your script to the kind that the destination OS uses.

      Thanks very much for the info. I appreciate it!
           - pikus
      "I want to live 'till I die. No more. No less." - Eddie Izzard
Line endings
by jhourcle (Prior) on Jul 12, 2004 at 02:17 UTC

    The issue is with line endings, but most likely not why you think.

    In the first line of the file, you'll have:

    #!/usr/bin/perl

    or the equivalent.

    If you transfer between a windows PC and a UNIX box, you end up with:

    #!/usr/bin/perl^M

    So, when you go to execute the script, it looks for 'perl^M' to execute, which it can't find. When you're dealing with CGIs, this can be a real problem to debug, as you'll get 'file not found' type error message which confuses people.

    Just to be safe, I recommend using the shebang line of:

    #!/usr/bin/perl --

    Typically, you can get away with bad line endings for most scripts this way, but I'm guessing '<<EOF' type declarations would be a problem, as would pod.

Re: FTPing
by bart (Canon) on Jul 12, 2004 at 11:42 UTC
    To be honest, it matters a lot less now than it used to, apart from the issue brought up by jhourcle.

    Modern perls do not care as much any more what you use for line endings on the server the script runs on. Both CRLF (Windows style) and just LF (Unix style) have always worked on Windows, and since 5.004_05 scripts in Windows/DOS text format work on Unix/Linux/etc. Hmm. That's longer than I thought.

      Thank you. That is an excellent piece of information to have. Thanks for the clarification.
           - pikus
      "I want to live 'till I die. No more. No less." - Eddie Izzard
Re: FTPing
by magawr (Initiate) on Jul 12, 2004 at 12:52 UTC
    The reasoning most probably refers to the conversion process that is automatically done during an ascii transfer versus a binary transfer.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2024-03-28 13:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found