簡體   English   中英

Perl SFTP使用Net :: SFTP :: Foreign發布

[英]Perl SFTP issues using Net::SFTP::Foreign

我正在使用Net :: FTP :: Foreign,我一直收到有關文件未找到的錯誤,我不確定我的語法是錯誤還是我誤解了如何使用它。

$LOGFILE = 'data_log' . $YYYYMMDD . '.log';

$sftp->setcwd('/tmp') 
    or die 'Unable to change working directory to /tmp: ' . $sftp->error;
print "CWD set\n";
my $ls = $sftp->ls('/tmp', names_only => 1, ordered => 1);

foreach my $file (@$ls) {
    print $file . "\n";
}

print 'Getting file: ' . $LOGFILE . "\n";
$sftp->get('/tmp/data_log*', 'data_log' . $YYYYMMDD . 'log') 
        or die 'Could not get remote file: ' . $sftp->error;

我得到的錯誤是遠程端沒有這樣的文件,但我確認當我執行LS cmd時它們確實存在。

我的腳本有什么明顯錯誤導致它不起作用嗎?

另外我使用的是Net :: SFTP :: Foreign,因為Net :: SFTP不會在運行10.7的MBP上構建

而不是get使用mget ,將轉移所有匹配給定模式的文件。

你有:

$sftp->get('/tmp/data_log*', 'data_log' . $YYYYMMDD . 'log') 

有沒有名為/tmp/data_log*的文件? 或者你想獲得/tmp中以data_log開頭的所有文件?

您只能使用get方法一次獲取一個文件。 全球不起作用。 為什么你不動get到您foreach循環? 當你看到你想要的文件時,抓住它。

foreach my $file ( @{$ls} ) {
    print qq(Found file "$file" in directory\n);

    # Is this the file we want to fetch?

    if ( $file eq $LOGFILE ) {
          print qq(Attempting to fetch "$file"\n);
          $sftp->get( "$LOGFILE" )   #I think you're only interested in this file
              or die qq(Could not fetch file "$LOGFILE" from directory: ) . $sftp->error;
          print qq(Fetched file "$file"\n);
    }
}

暫無
暫無

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

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