Created
April 28, 2015 05:19
-
-
Save yevrah/0db0f4aef865154e44eb to your computer and use it in GitHub Desktop.
Perl: Download files using libcurl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use WWW::Curl::Easy; | |
use File::Temp qw/tempfile/; | |
my ($out, $filename) = tempfile(); | |
my $curl = WWW::Curl::Easy->new(); | |
$curl->setopt(CURLOPT_URL, "https://github.com/libwww-perl/libwww-perl/archive/6.13.zip"); | |
$curl->setopt(CURLOPT_WRITEDATA,$out); | |
$curl->setopt(CURLOPT_VERBOSE,1); | |
$curl->setopt(CURLOPT_FOLLOWLOCATION,1); | |
my $retcode = $curl->perform(); | |
if ($retcode != 0) { | |
print STDERR "Fetch Failed: ", $curl->strerror($retcode), " ( +$retcode)\n"; | |
print STDERR "errbuf: ", $curl->errbuf; | |
exit(1); | |
} else { | |
print STDERR "Fetched file to: ", $filename, "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment