in reply to CrLf getting inserted into an octet-stream (gzip file)

You want to use binmode when writing binary content.

You could also let LWP::UserAgent store the response content to disk directly, depending on your needs:

$ua->post( ':content_file' => $filename, ... );

or, if this is an exercise to send the file to a client, give quicker feedback through a callback (but here you still have to binmode STDOUT):

$ua->post( ':content_callback' => sub { print $_[0] }, ... );

Replies are listed 'Best First'.
Re^2: CrLf getting inserted into an octet-stream (gzip file)
by Rumtis (Initiate) on May 23, 2008 at 17:11 UTC
    Thanks Corion
    Setting binmode would do it, but I'm trying to write some cleaner code and use the content_file parameter
    I've changed my post call to
    my $response = $ua->post( $url, ':content_file' => '.\test.gz', Content_Type => 'form-data', Content => [ userid => 'USERID', password => 'PASSWORD', recordlength => '', recordterminator => 'NONE', remotefilename => 'REMOTE_FILENAME' ] );
    However, I'm not getting the test.gz file written out. I figure I'm doing (or not doing) something stupid, but I'm not seeing it.
    So I'm apprealing to the monks again to help me past my stupidity.
    Thanks for you help, though.

      Most likely, the current directory is not what you think it is, or the user your program is running as has not sufficient rights to write to the file.

      Consider using an absolute path to save the file. That way you become independent of what the current directory is.

      As an aside, you might want to be careful when using backslashes. In most cases, you can use forward slashes even on Windows, and forward slashes don't have the danger of getting interpreted as escapes:

      ':content_file' => 'c:/temp/test.gz',
        Absoluted the path (with forward slashes) and I know I have rights to the directory (I have admin rights to the box).

        Oh well, I'll go the long route.

        Thanks again for your help.