如何使用scp_get或scp_put将文件从远程服务器复制到另一台远程服务器

时间:2019-01-28 07:08:00

标签: perl scp openssh

我正在尝试使功能自动化。我想使用Perl将文件从远程服务器复制到另一台远程服务器。我该如何实现?

我尝试了以下代码:

#!/ats/bin/perl

use Net::OpenSSH;
use Data::Dumper;


my $source_ip = "<IP_SOURCE>";
my $credentials = {username=>'root', password=>'root@123'};


my $ssh_obj = Net::OpenSSH->new(
                $source_ip,
                user     => $credentials->{username},
                password => $credentials->{password},

            );



my $source = "root@<IP_REMOTE>/home/user/test.txt";
my $dest = "root@<IP_REMOTE_2>:/tmp/"; #Destination is a target folder in the device with the source IP. But I want it another remote IP here.
unless($ssh_obj->{SSH}->scp_get({recursive => "1", glob => 1}  , $source , $dest))
{
    print("Yoda says: 'ERROR this is. Need to fix you must'");
}

现在,我可以登录到远程服务器,然后从那里执行SCP。我只是想知道是否可以通过在另一台第三台服务器上运行perl脚本来从一台远程服务器向另一台远程服务器启动scp。

0 个答案:

没有答案