+ -
当前位置:首页 → 问答吧 → 自动从ftp下载文件(不回显输入密码)

自动从ftp下载文件(不回显输入密码)

时间:2011-01-19

来源:互联网

  1. #!/usr/bin/perl
  2. #===============================================================================
  3. #
  4. #         FILE:  autoftp.pl
  5. #
  6. #        USAGE:  ./autoftp.pl  
  7. #
  8. #  DESCRIPTION:  Download data from ftp automatically
  9. #
  10. #      OPTIONS:  ---
  11. # REQUIREMENTS:  ---
  12. #         BUGS:  ---
  13. #        NOTES:  ---
  14. #       AUTHOR:  Will
  15. #      COMPANY:  CNNDC
  16. #      VERSION:  1.0
  17. #      CREATED:  11/18/2010 03:06:49 AM
  18. #     REVISION:  ---
  19. #===============================================================================

  20. # use strict;
  21. use warnings;
  22. use Net::FTP;
  23. use Term::ReadKey;

  24. die "Usage:\n\t$0  [user]\@Server:file\n" if (!scalar @ARGV);
  25. my ($user, $password, $server, $file) = qw#anonymous anonymous@mail#;
  26. my $debug=0;

  27. ($server, $file) = $ARGV[0] =~ /\@?([\w\d]+):([\w\W]+)/;
  28. if ( $ARGV[0] =~ /([\w\W]+)\@/ ) {
  29.         $user = $1;       
  30.         print "Input password: ";
  31.         ReadMode 2;
  32.         chomp($password=<STDIN>);
  33.         ReadMode 0;
  34. }
  35. # print "$user, $password, $server, $file\n";

  36. my $ftp = Net::FTP->new("$server", Debug => $debug)
  37.         or die "Can NOT connect to $server. $@";
  38. $ftp->login("$user", "$password")
  39.         or die "Can NOT loggin. ", $ftp->message;
  40. $ftp->binary()
  41.         or die "Can NOT set binary mode. ", $ftp->message;
  42. $ftp->get("$file")
  43.         or die "get $file failed. ", $ftp->message;
  44. $ftp->quit;
复制代码

作者: lockend   发布时间: 2011-01-19

不回显输入密码:

我觉得可以调用shell命令来完成:



QUOTE:
if ( $ARGV[0] =~ /([\w\W]+)\@/ ) {
       $user = $1;      

         system "stty  -echo";
          print "Input password: ";
        chomp($password=<STDIN> );
          system "stty echo ";
     
}

作者: jiannma   发布时间: 2011-01-21