Hello!

I am trying to write a perl script using WWW:::Mechanize, to download a dictionary file from a server.

The file is a zip file. The program given below (error checks have been purposely removed),
This program runs without any errors/warnings,
and i can see the file downloaded in the specified location.

The download is supposed to get me a zip file,
but when i open the file using winzip/winrar i get an error.
When i download it as .zip, opening with winzip gives this error:"filename: start of central directory not found; Zip file corrupt. Possible cause:file transfer error."
When i download it as .tar, winzip gives this error:"Error reading header after processing 0 entries."
Winrar gives this error "<filename>: Unexpected end of archive".

The server is on a Free BSD machine, my program is on running on Windows(Active Perl 5.8.7)

I'm surely missing something here, and cannot find a way out of this problem! :(

I had sent this message to perl-beginners/ libwww lists earlier but no response.

Hence posting again :)
Please help!
Best regards,
Dhanashri
==========================

#!/usr/bin/perl -w use strict; use WWW::Mechanize; my $login = "admin"; my $password = "pass"; my $url = "http://abc.xyz.com"; my $mech = WWW::Mechanize->new(); $mech->get($url); #Log in print "\n\n\n\nLogging in.... \n\n\n\n"; $mech->submit_form( form_number => 1, fields => { user => $login, password => $password }, ); #Navigate to the download page $mech->follow ( 'Download' ); if ($mech->success) { #this page has only one form with the "download" button. #Download is for a zip file. $mech->click(); if ($mech->success) { my $filename = 'E:\Dhanashri\down.zip'; $mech->save_content ( $filename ); print "\nFile Downloaded!\n\n"; } else { print "\nDownload Failed!\n"; } } print "Logging out...\n"; $mech->follow ( 'logout' );
============================

In reply to Using Mechanize to download a zip file? by dhanu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.