Skip navigation.
Home
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.

Example:

#!/usr/bin/perl
 
use Net::FTP;
 
my host = ftp.yourftpserver.com
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: $!";