0
我想從使用sftp實用程序的特定文件夾下載幾個文件,並通過Expect.pm來完成它。下面是該代碼:使用Expect.pm運行sftp命令
use strict;
use Expect;
my $userid = `whoami`;
chomp($userid);
my $Password = "<password>";
my $command = "sftp " . "$userid" . "\@<server-name>";
my $spawn_ok = 0;
my $timeout = 10;
print "$command \n";
my $exp = new Expect();
$exp->log_file("FTPLOGFILE.txt");
$exp->spawn("$command") or die "Cannot spawn $command: $!\n";
$exp->log_stdout(0);
$exp->expect($timeout,
[ 'Password:',
sub {
$spawn_ok = 1;
my $fh = shift;
print "Sending password \n";
$fh->send("$Password\r");
exp_continue;
}
],
[ 'sftp> ',
sub {
my $fh = shift;
$spawn_ok = 3;
print "Downloading cfg files \n";
$fh->send("get /home/cfg/*.cfg /tmp/ACC_CCM_CFG","\n");
$fh->send("bye","\n");
exp_continue;
}
]
的問題是除了從網上下載文件到上面的目錄:/ tmp目錄/ ACC_CCM_CFG我也想運行相同的SFTP會話中下面的命令: GET /家/申請/*.pl/tmp/ACC_CCM_APPL 但是我不能這樣做,因爲expect函數的正則表達式是相同的(sftp>)。如果提示的正則表達式沒有改變,我如何在預期的同一個sftp會話中運行一系列命令。
請在上面提一下,因爲我找不到任何解決方案。
使用Net :: SFTP :: Foreign – salva