How to Transfer URLs from the Command Line

Posted by Prolific Programmer Sun, 03 Aug 2008 23:09:00 GMT

While Mac OS X includes lukem's ftp client, Ubuntu does not. However, one can make a perl script to fetch a URL is trivial. Indeed, one is included below. Works everywhere perl does... Enjoy.

use warnings;
use strict;
use diagnostics;
use Net::FTP;
use URI;
my $uri = shift @ARGV;
die "Usage: $0 ftp-url\n" if not defined $uri;
my $url = URI->new($uri);
die "need FTP URL to work\n" unless $url->scheme =~ /ftp/;
my $conn = Net::FTP->new($url->host) or die "$!";
$conn -> get($url->path);
$conn -> quit;