Perl Net::SFTP::外部断开连接未关闭连接
调用Perl Net::SFTP::外部断开连接未关闭连接,perl,Perl,调用$sftp->disconnect()时,连接没有关闭,Perl脚本处于挂起状态,直到我手动终止该进程 下面是我们如何创建SFTP连接的代码: my %sftp_args = ( user => $username, autodie => 1, stderr_discard => 1,more => qw(-v), timeout => $timeout_secs,ssh_cmd => $SSH_PATH );
$sftp->disconnect()
时,连接没有关闭,Perl脚本处于挂起状态,直到我手动终止该进程
下面是我们如何创建SFTP连接的代码:
my %sftp_args = ( user => $username, autodie => 1, stderr_discard => 1,more => qw(-v),
timeout => $timeout_secs,ssh_cmd => $SSH_PATH );
my $sftp = Net::SFTP::Foreign->new($remote_host, %sftp_args);
当我们调用disconnect方法时,脚本被挂起
$sftp->disconnect();
我试着在警报下将断开连接置于eval,但它仍然没有回来
eval {
local $SIG{ALRM} = sub { die "alarm\n" };
alarm 25;
my $retrun = $sftp->disconnect();
alarm 0;
};
my $exception = $@;
msg("Error Dump".Dumper($exception));
}
下面是我在nohup.out文件中遇到的错误
bash: line 1: 27860 Alarm clock sftp_connection.pl
在对Net::SFTP::Foreign模块进行分析之后,我找到了解决方案。所以Net::SFTP::Foreign模块有一个bug下面是详细信息,我在perldoc中发现了这个bug:
On some operating systems, closing the pipes used to communicate the
slave SSH process does not terminate it and a work around has to be applied.
If you find that your scripts hung when the $sftp object gets out of scope,
try setting $Net::SFTP::Foreign::dirty_cleanup to a true value
根据上述意见,我对我的申请进行了更改,现在它运行良好:
my %sftp_args = ( user => $username, autodie => 1, stderr_discard => 1,
timeout => $timeout_secs, ssh_cmd => $SSH_PATH, dirty_cleanup => 1 );
my $sftp = Net::SFTP::Foreign->new($remote_host, %sftp_args);
return $sftp;
您是否尝试了
undef$sftp代码>?@vkk05不,我没试过。