Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: convert files unix2dos using perl script

by hbo (Monk)
on Jun 21, 2004 at 06:53 UTC ( #368378=note: print w/ replies, xml ) Need Help??


in reply to convert files unix2dos using perl script

Well, the ascii() method is supposed to enable line ending translation between differing clients and servers. You should try a manual ftp to see whether or not it works that way. If it doesn't, here's some code to do it yourself in place:

open TR, "unix2dos $File |" or die $!; # Or FQ path $ftp->binary(); # We translate, not the server. $ftp->put(TR,$File); # must give remote name.


Comment on Re: convert files unix2dos using perl script
Download Code
Replies are listed 'Best First'.
Re^2: convert files unix2dos using perl script
by cc (Beadle) on Jun 21, 2004 at 09:26 UTC
    thanks,but I get ERROR:
    "Bareword "TR" not allowed while "strict subs" in use at test.cgi line 28.
    Execution of test.cgi aborted due to compilation errors."

    on this line:
    $ftp->put(TR,$File); # must give remote name.

    any idea what could be wrong ?
    greetings
    cc
      Perl doesn't know you mean to pass a filehandle to that method, so it passes the bareword "TR" instead. You could try to pass \*TR instead.
      $ftp->put(\*TR,$File);
      Better yet, for a recent enough perl, use a lexical variable to hold the filehandle. It'll look cleaner.
      open my($tr), "unix2dos $File |" or die $!; # Or FQ path $ftp->binary(); # We translate, not the server. $ftp->put($tr,$File); # must give remote name.

      But, IMO, it's overkill to call an external program to handle this little task. Perl will convert line endings for you, when reading from a handle in text mode. Internally, on Windows, text data is Unix text data. So, all you need to do is open the file.

      open my($fh), $File or die $!; $ftp->binary(); # We translate, not the server. $ftp->put($fh,$File); # must give remote name.

      p.s. I really wonder why just transferring data in Ascii mode won't work. Are you sure you don't accidently have double carriage returns in your files?

        If I try
        $ftp->put(\*TR,$File);
        220 ttn208 Microsoft FTP Service (Version 5.0).
        Net::FTP=GLOB(0x834a938)>>> user anonymous
        Net::FTP=GLOB(0x834a938)<<< 331 Password required for anonymous.
        Net::FTP=GLOB(0x834a938)>>> PASS ....
        Net::FTP=GLOB(0x834a938)<<< 230 User anonymous logged in.
        Net::FTP=GLOB(0x834a938)>>> CWD /IN
        Net::FTP=GLOB(0x834a938)<<< 250 CWD command successful.
        unix2dos: converting file /home/transferfile to DOS format ...
        Net::FTP=GLOB(0x834a938)>>> TYPE I
        Net::FTP=GLOB(0x834a938)<<< 200 Type set to I.
        Net::FTP=GLOB(0x834a938)>>> PORT X,X,X,X,128,156
        Net::FTP=GLOB(0x834a938)<<< 200 PORT command successful.
        Net::FTP=GLOB(0x834a938)>>> STOR /home/transferfile
        Net::FTP=GLOB(0x834a938)<<< 550 /home/transferfile: The system cannot find the path specified.

        open my($tr), "unix2dos $File |" or die $!; # Or FQ path $ftp->binary(); # We translate, not the server. $ftp->put($tr,$File); # must give remote name.
        ...............................................................................
        550 /home/transferfile: The system cannot find the path specified.

        open my($fh), $File or die $!; $ftp->binary(); # We translate, not the server. $ftp->put($fh,$File); # must give remote name.
        ...............................................................................
        550 /home/transferfile: The system cannot find the path specified. -bash: 550: command not found

        and I don't get any transfer, but the path to the file is correct.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://368378]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (12)
As of 2015-07-29 12:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (263 votes), past polls