For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > October 2005 > Zip file download using WWW::Mechanize









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Zip file download using WWW::Mechanize
Dhanashri Bhate

2005-10-26, 7:55 am

Hello All,



The following code snippet is of a program I've written to download a
dictionary file from a server. The file to be downloaded is a zip..



Kindly see the code below, (error checkings etc are purposely removed from
the script, to keep the message small).

The program runs without any errors, and i can a file downloaded in
specified location. The file is also of the right size (compared with the
manually downloaded file).

But cannot open this file using Winzip



When i download it as .zip, as in the snippet above, opening thr' winzip
gives this error:

"filename: start of central directory not found; Zip file corrupt. Possible
cause:file transfer error."



When i download it the file as .tar, winzip gives this error:

"Error reading header after processing 0 entries."



The server from where i am getting this file is a Free BSD machine, my
program is on Windows(Active Perl 5.8.7)



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

#!/usr/bin/perl -w



use strict;

use WWW::Mechanize;



my $login = "administrator";

my $password = "admin";



my $url = "http://abc.xyz.com";



my $mech = WWW::Mechanize->new();

$mech->get($url);



#Log in

$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\Perl-study\downbrand.zip';

$mech->save_content ( $filename );

print "\nFile Downloaded!\n\n";

}

else

{

print "\nDownload Failed!\n";

}

}



$mech->follow ( 'logout' );

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



Thanks,

Dhanashri


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com