在通过 scp/sftp 将 $cmd 输出复制到第二台服务器时需要帮助。我有这个代码;工作正常,但需要很长时间,因为 $ cmd 输出约为 700MB,15000 行。
use warnings;
use Net::SSH2;
my ($host, $user, $password, $outfile) = @ARGV;
my $cmd = "show zoneset active";
my $ssh = Net::SSH2->new();
$ssh->connect($host);
$ssh->auth_keyboard($user, $password);
my $channel = $ssh->channel();
$channel->exec($cmd);
open OUTPUT, ">", "$outfile";
while (<$channel>) { print OUTPUT };
$channel->close;
$ssh->disconnect;