簡體   English   中英

Perl Net::SFTP::Foreign disconnect 不關閉連接

[英]Perl Net::SFTP::Foreign disconnect not closing the connection

在調用$sftp->disconnect()連接沒有關閉,Perl 腳本處於掛起狀態,直到我手動$sftp->disconnect()進程。

下面是我們如何創建 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);

當我們調用斷開連接方法時,腳本被掛起。

$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 Module 進行分析后,我找到了解決方案。 所以 Net::SFTP::Foreign 模塊有一個錯誤,下面是詳細信息,我在 perldoc 中找到了這個:

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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM