我在 Perl 中编写了以下脚本(我是 Perl 新手),它尝试通过 SCP 将文件发送到远程机器。我正在尝试使用 Expect 传递密码。到目前为止,脚本如下所示:
#!/usr/bin/perl
use Net::FTP;
use Net::SCP;
use Net::SCP::Expect;
sub scp_backup{
$n = scalar(@_);
if ($n == 7)
{ my $scp_conn = Net::SCP->new($ip, $username) or die "\nCan't open $ip";
#die
my $dest="/my/remote/location/";
my $testfile = "/pah/to/my/file/testing.txt";
unless ($scp_conn->scp($testfile => $dest))
{ my $scp_conn_ex = Net::SCP::Expect->new;
$scp_conn_ex->login($username, $password);
}
}
else
{
print "\nNot enough args\n\n";
}
print "\nTotal items passed:$n\n";
}
$name = "testuser";
$tfr_type = "scp";
$ip = "XX.XX.XX.XX";
$username = 'testuser_name';
$password = 'testpass';
&scp_backup($name, $tfr_type, $ip, $username, $password);
但是,转移似乎没有发生。此外,不会引发任何错误。我哪里出错了?