Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use lib '.';
- use lib '/usr/lib/perl5/vendor_perl/5.8.0';
- use Net::FTPSSL;
- use POSIX 'strftime';
- sub send_dir {
- my $mask = $_[1] . '/*';
- #print $mask, "\n";
- my @files = glob $mask;
- foreach $file (@files) {
- if (-f $file) {
- print "File $file\n";
- $_[0]->put($file)
- or die "Can't put: ", $ftps->$last_message();
- }
- if (-d $file) {
- print "Dir $file\n";
- @parts = split(/\//, $file);
- $_[0]->mkdir($parts[-1]);
- $_[0]->cwd($parts[-1]);
- send_dir($_[0], $file);
- }
- }
- $_[0]->cwd('..');
- }
- $server = '127.0.0.1';
- $port = 21;
- $user = 'ftp';
- $password = '';
- $remote_dir = '.';
- $local_dir = 'somedir';
- $num_args = $#ARGV + 1;
- foreach $argnum (0 .. $#ARGV) {
- if ($ARGV[$argnum] eq '--host') { $server = $ARGV[$argnum + 1]; }
- if ($ARGV[$argnum] eq '--port') { $port = $ARGV[$argnum + 1]; }
- if ($ARGV[$argnum] eq '--user') { $user = $ARGV[$argnum + 1]; }
- if ($ARGV[$argnum] eq '--password') { $password = $ARGV[$argnum + 1]; }
- if ($ARGV[$argnum] eq '--remote-dir') { $remote_dir = $ARGV[$argnum + 1]; }
- if ($ARGV[$argnum] eq '--local-dir') { $local_dir = $ARGV[$argnum + 1]; }
- }
- my $ftps = Net::FTPSSL->new($server,
- Port => $port,
- Encryption => 'E',
- Debug => 1)
- or die "Can't connect";
- $ftps->login($user, $password)
- or die "Can't login: ", $ftps->$last_message();
- $ftps->cwd($remote_dir)
- or die "Can't cd to $remote_dir: ", $ftps->$last_message();
- $now_string = strftime "%e-%m-%Y_%H:%M ", localtime;
- $ftps->mkdir($now_string);
- $ftps->cwd($now_string);
- send_dir($ftps, $local_dir);
- $ftps->quit();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement