Advertisement
Guest User

Untitled

a guest
May 20th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. use lib '.';
  2. use lib '/usr/lib/perl5/vendor_perl/5.8.0';
  3. use Net::FTPSSL;
  4. use POSIX 'strftime';
  5.  
  6. sub send_dir {
  7. my $mask = $_[1] . '/*';
  8. #print $mask, "\n";
  9. my @files = glob $mask;
  10.  
  11. foreach $file (@files) {
  12. if (-f $file) {
  13. print "File $file\n";
  14. $_[0]->put($file)
  15. or die "Can't put: ", $ftps->$last_message();
  16. }
  17. if (-d $file) {
  18. print "Dir $file\n";
  19. @parts = split(/\//, $file);
  20. $_[0]->mkdir($parts[-1]);
  21. $_[0]->cwd($parts[-1]);
  22. send_dir($_[0], $file);
  23. }
  24. }
  25. $_[0]->cwd('..');
  26. }
  27.  
  28. $server = '127.0.0.1';
  29. $port = 21;
  30. $user = 'ftp';
  31. $password = '';
  32. $remote_dir = '.';
  33. $local_dir = 'somedir';
  34.  
  35. $num_args = $#ARGV + 1;
  36. foreach $argnum (0 .. $#ARGV) {
  37. if ($ARGV[$argnum] eq '--host') { $server = $ARGV[$argnum + 1]; }
  38. if ($ARGV[$argnum] eq '--port') { $port = $ARGV[$argnum + 1]; }
  39. if ($ARGV[$argnum] eq '--user') { $user = $ARGV[$argnum + 1]; }
  40. if ($ARGV[$argnum] eq '--password') { $password = $ARGV[$argnum + 1]; }
  41. if ($ARGV[$argnum] eq '--remote-dir') { $remote_dir = $ARGV[$argnum + 1]; }
  42. if ($ARGV[$argnum] eq '--local-dir') { $local_dir = $ARGV[$argnum + 1]; }
  43. }
  44. my $ftps = Net::FTPSSL->new($server,
  45. Port => $port,
  46. Encryption => 'E',
  47. Debug => 1)
  48. or die "Can't connect";
  49.  
  50. $ftps->login($user, $password)
  51. or die "Can't login: ", $ftps->$last_message();
  52.  
  53. $ftps->cwd($remote_dir)
  54. or die "Can't cd to $remote_dir: ", $ftps->$last_message();
  55.  
  56. $now_string = strftime "%e-%m-%Y_%H:%M ", localtime;
  57. $ftps->mkdir($now_string);
  58. $ftps->cwd($now_string);
  59.  
  60. send_dir($ftps, $local_dir);
  61.  
  62. $ftps->quit();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement