AndriesKeun
asked on
Perl Script Copy to FTP
Hi there
I have a linux web server running a MySQL database and I want to set up a CRON job to copy the database to my FTP account on a daily basis. I need a PERL script to do the following:
1) Connect to FTP account (hostname, username and password)
2) Copy database using the following command: mysqlhotcopy db_name /path/to/some/dir (run from linux shell)
Sorry, I have little experience in Perl, therefore 500 points goes to a working script.
I have a linux web server running a MySQL database and I want to set up a CRON job to copy the database to my FTP account on a daily basis. I need a PERL script to do the following:
1) Connect to FTP account (hostname, username and password)
2) Copy database using the following command: mysqlhotcopy db_name /path/to/some/dir (run from linux shell)
Sorry, I have little experience in Perl, therefore 500 points goes to a working script.
"$ftp->get($_) or warn "put failed ", $ftp->message;"
should probably be:
$ftp->put($_) or warn "put failed ", $ftp->message;
should probably be:
$ftp->put($_) or warn "put failed ", $ftp->message;
ASKER
Sorry it took so long to respond, been so busy and totally forgot about this.
The script is not working properly. What it is doing is it is copying the DB files to the same directory as the DB, and not to the FTP. No files are copied to the FTP, and no error message come up.
I extra thing to add, how would I create a directory with todays date, i.e. create a directory with the name of '14-09-2007' or similar.
Many Thanks
The script is not working properly. What it is doing is it is copying the DB files to the same directory as the DB, and not to the FTP. No files are copied to the FTP, and no error message come up.
I extra thing to add, how would I create a directory with todays date, i.e. create a directory with the name of '14-09-2007' or similar.
Many Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
my $dbname = "Your_DB_Name_here";
my $destdir = "/your/dest/dir/here";
my $hostname = "your.host.name.here";
my $user = "username";
my $pass = "pass";
system("mysqlhotcopy $dbname $destdir");
chdir($destdir);
my @files=<*>;
my $ftp = Net::FTP->new($hostname, Debug => 0) or die "Cannot connect to $hostname: $@";
$ftp->login($user,$pass) or die "Cannot login ", $ftp->message;
foreach (@files) {
$ftp->get($_) or warn "put failed ", $ftp->message;
}
$ftp->quit;