2013年3月8日 星期五

使用 perl 做 scp 的二種方式

使用 perl 做 scp 的二種方式

#yum install  libssh2-devel
#yum install   libssh2
#yum install   perl-Net-SSH2
#yum install perl-Net-SFTP

========================================================
#!/usr/bin/perl
use Net::SFTP;
$sftp = Net::SFTP->new('xxx.xxx.xxx.xxx',user=>'userID',password=>'userPWD');
$sftp->get("/xxx/xxx", "/xxx/xxx");
========================================================
#!/usr/bin/perl
@ip=qw
(
 192.168.1.1
 192.168.1.2
);
@host=qw
(
 server1
 server2
);

@list=qw
(
 server1.txt
 server1.txt
);

for ($x=0;$x<=$#ip;$x++) {
     print " \n $x SCP IP :  $ip[$x]  HostName :  $host[$x] DFCHK_File : $df[$x] \n";
     sshget();
}
sub sshget {
 use Net::SSH2;
 use Net::SSH2::Dir;
 $ssh=Net::SSH2->new() or die "couldn't make SSH object\n";
 #$ssh->debug(1);
 $ssh->blocking(1);
 print "made SSH object\n";
 $ssh->connect("$ip[$x]") or die "couldn't connect to host\n";
 print "connected to $host[$x] $ip[$x] \n";
 $ssh->auth_password('userID','userPWD') or die "couldn't authenticate user \n";
 print "authenticated UserID\n";
 $ssh->scp_get("/xxx/$list[$x]","/xxx/$list[$x]") or warn "couldn't get file in $list[$x] \n ";
 print "\n Download  Successfully \n";
 $ssh->disconnect or die "couldn't disconnect\n";
}
========================================================

沒有留言:

張貼留言