#!/usr/bin/perl -w # bak.pl - by dual # # Backs up and uploads a file # # Usage: perl bak.pl ############################# use strict; use Cwd; use File::Copy; use MIME::Base64; use Net::FTP; # Get info my $file = shift or die ">>> Usage: perl bak.pl \n"; my $string1 = 'BASE64USERSTRING'; my $string2 = 'BASE64PASSSTRING'; my $home_dir = $ENV{'HOME'}; my $current_dir = getcwd; my $copy_dir = $current_dir; my $backup_dir = '/BACKUP/DIR'; my $dstring1 = decode_base64($string1); my $dstring2 = decode_base64($string2); # Chomp chomp($dstring1); chomp($dstring2); # Set directories $current_dir =~ s/$home_dir\/WEBSITEDIR//; $copy_dir =~ s/$home_dir/$backup_dir/; # Back up file and print status print ">>> Backing up $file..."; copy("$file","$copy_dir/$file") or die ">>> Back up failed: $!"; print " done!\n"; # Create FTP object and login my $ftp = Net::FTP->new("EXAMPLE.COM", Debug => 0 , Passive => 1) or die ">>> Connection failed: $@"; $ftp->login("$dstring1","$dstring2") or die ">>> Login failed: ", $ftp->message; # Try binary for everything $ftp->binary(); # Change directory and upload print ">>> Uploading $file..."; $ftp->cwd("$current_dir") or die ">>> Traversal failed: ", $ftp->message; $ftp->put("$file") or die ">>> Upload failed: ", $ftp->message; # Closing message and exit $ftp->quit; print " done!\n"; exit 0;