Skip to content

Instantly share code, notes, and snippets.

@krisk0
Created June 1, 2026 14:21
Show Gist options
  • Select an option

  • Save krisk0/ebde270b49f1a82876fc51b84f43578a to your computer and use it in GitHub Desktop.

Select an option

Save krisk0/ebde270b49f1a82876fc51b84f43578a to your computer and use it in GitHub Desktop.
download file via perl LWP module
#!/usr/bin/perl
use strict;
use warnings;
use LWP::UserAgent;
my $url = 'https://github.com/AUTHOR/REPOSITORY/archive/refs/heads/master.zip';
my $filename = '/tmp/main.zip';
my $ua = LWP::UserAgent->new;
$ua->timeout(30);
$ua->proxy(['http', 'https'], 'http://proxy.boss.com:3128');
my $response = $ua->get($url);
if ($response->is_success) {
open(my $fh, '>', $filename) or die "Cannot open '$filename' for writing: $!";
binmode $fh;
print $fh $response->content;
close $fh;
print "File downloaded successfully.\n";
} else {
die "Download failed: ", $response->status_line;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment