【问题标题】:Perl SFTP issues using Net::SFTP::Foreign使用 Net::SFTP::Foreign 的 Perl SFTP 问题
【发布时间】:2012-04-17 16:53:28
【问题描述】:

我正在使用 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 上构建

【问题讨论】:

    标签: perl


    【解决方案1】:

    使用mget 代替get,它将传输与给定模式匹配的所有文件。

    【讨论】:

      【解决方案2】:

      你有:

      $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);
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-22
        • 1970-01-01
        • 1970-01-01
        • 2013-09-21
        • 2019-09-23
        • 2013-10-18
        相关资源
        最近更新 更多