Skip navigation.
Your source for Perl tips, howto's, faq and tutorials
( categories: )

Use Net::FTP module. The functions are named like the corresponding ftp commands, so it's very easy to use.


use Net::FTP;
my host =
my $username = "yourusername";
my $password = "yourpassword";
my $ftpdir = "/your/ftp/path";
my $file = "yourfile";
#-- connect to ftp server
my $ftp = Net::FTP->new($host) or die "Error connecting to $host: $!";
#-- login
$ftp->login($username,$password) or die "Login failed: $!";
#-- chdir to $ftpdir
$ftp->cwd($ftpdir) or die "Can't go to $ftpdir: $!";
#-- download file
$ftp->get($file) or die "Can't get $file: $!";
#-- close ftp connection
$ftp->quit or die "Error closing ftp connection: $!";