Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display LWP::UserAgent download progress

I'm downloading a large file directly to a file with Perl using LWP::UserAgent and the :content_file option.

This is a simplified example of my code:

require LWP::UserAgent;

my $ua = LWP::UserAgent->new;
$ua->timeout(3600);
$ua->env_proxy;

my $response = $ua->get(
    'http://example.com/largefile.xml',
    :content_file   => 'path/to/file/largefile.xml'
);

if ($response->is_success) {
    print "File downloaded\n";
}
else {
    die $response->status_line;
}

Is there any way to display the percentage of the download status? (or something similiar to wget output)

10% [===>                                  ]  65.120.154  527K/s 
like image 943
nanocv Avatar asked Nov 09 '16 16:11

nanocv


2 Answers

From the documentation for the module.

$ua->show_progress

$ua->show_progress( $boolean )

Get/set a value indicating whether a progress bar should be displayed on the terminal as requests are processed. The default is FALSE.

like image 56
Dave Cross Avatar answered Oct 02 '22 19:10

Dave Cross


Dave has already answered your question but I would like to suggest below 2 modules.

  • LWP::UserAgent::ProgressBar: A subclass of LWP::UserAgent that provides additional methods get_with_progress and post_with_progress.

  • LWP::UserAgent::ProgressAny: Uses Progress::Any framework, therefore, it can be used to record progress to any output.

like image 32
Chankey Pathak Avatar answered Oct 02 '22 19:10

Chankey Pathak