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

I'm using Archive::zip in my program to zip up a few text files on my linux box and ftp them over to an NT machine.
For some reason, there is some 'formatting' in these text files by the time they reach the NT box. They still work correctly, but they just look strange when viewing with notepad or something. HOWEVER, they look just fine when viewing with 'Wordpad - or Word'.
Question: how can I get rid of this formatting that was not there in the first place? Has anyone else run into something like this?

I am ftp'ing in binary format (will not work in ascii since it is a zip file). Here is an example of the code I am using:

#!/usr/bin/perl use Net::FTP; use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); $zip = Archive::Zip->new(); $member = $zip->addFile('some_file.txt'); $member = $zip->addFile('some_file2.txt'); $member = $zip->addFile('some_file3.txt'); die 'write error' if $zip->writeToFileNamed('some_zip_file.zip') != AZ +_OK; $ftp = Net::FTP->new("some_ip"); $ftp->login('user', 'pass'); $ftp->type("I"); # zip file is a binary file. $ftp->put('some_zip_file.zip'); $ftp->quit();
Thanks for any help or pointers.

Replies are listed 'Best First'.
Re: unwanted text formatting with Archive::zip
by larryl (Monk) on Mar 15, 2001 at 23:30 UTC

    When you transfer a file in ASCII/text mode, the ftp client will normally convert carriage return and linefeed characters as needed for the destination system. Your ftp is not adding any formatting, it is simply preserving what is already in the files on the Linux side. You are correct in transferring the zip file as binary, however the file *within* the zip file are still in their original format. You either need to convert them before adding them to the zip file, or convert them after they hit the NT side.

    Don't know for sure about Linux, but on my Solaris machine there is a "unix2dos" command which does that type of conversion. If you want to try converting the files yourself before zipping, you can probably get away with something like s/\n/\r\n/g if it's plain text.

Re: unwanted text formatting with Archive::zip
by the_slycer (Chaplain) on Mar 15, 2001 at 23:42 UTC
    perl -e "while(<>){s/\n/\r\n/;print}" inputfile
    This is before zipping of course :-)
      perl -pe "s/\n/\r\n/" inputfile might be easier to type. ;) The -p wraps your code in a block like this:
      while(<>){ your_code } continue { print; }

      -n does that without the continue and print. Remember that Perl was invented by the constructively lazy. The got tired of typing while(<>){print} around their code all the time!

      --
      $you = new YOU;
      honk() if $you->love(perl)

Re: unwanted text formatting with Archive::zip
by dvergin (Monsignor) on Mar 15, 2001 at 23:43 UTC
    Following up on larryl's explanation...

    A quick-and-dirty way of fixing the line terminators on Windows is to load the document into Word and then save it again. As you have noticed, Word is smart enough to figure out what is happening with the line ends, and if you save the loaded file, it will then save it in Windows style.