#!/usr/bin/perl # upsite.pl - by Davidcopperfield # uploads a local directory to a server via ftp # usage: ./upsite.pl server user pass directory use Net::FTP; use strict; #Server my $server = $ARGV[0]; #Username my $user = $ARGV[1]; #Password my $pass = $ARGV[2]; #Directory on localhost to download to my $localdir = $ARGV[3]; my @files; #Files in current directory my @dirs = '/'; #Directories #FTP client my $ftp = Net::FTP->new($server, Debug => 0, passive => 1) or die "Cannot connect to $server : $@"; #Login to remotehost $ftp->login($user,$pass) or die "Cannot login: $@"; #Binary transfer mode $ftp->binary; #Put all files #Erase everything on remotehost first $ftp->rmdir('/',"true"); #Start of directory list @dirs = $localdir; #Loop through directories putting files and making directories foreach my $dir (@dirs) { #Change to new directory chdir $dir; #Make directory on remotehost $dir = substr($dir,length($localdir)); $ftp->mkdir($dir); #Find all the files in current directory @files = <*>; foreach my $file (@files) { #Check if it is a "normal" file (Assume lack of extension means directory if ($file=~/.*\..*/) { #Put file to corresponding place on remotehost print "Putting: $file to $dir\n"; $ftp->put("$localdir/$dir/$file","$dir/$file"); } else { #Add directory to list print "Making directory: $dir/$file\n"; push @dirs, "$localdir/$dir/$file"; } } } #Close connection $ftp->quit;