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 },

);

 

#checking for success etc...

 

#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' );

============================================================================
=================

Reply via email to