自从我使用 perl 以来已经有一段时间了,我正在尝试打印出 SFTP 服务器上的文件列表。
这是我的 Perl 脚本 -
#! /usr/bin/env perl
use strict;
use warnings;
use feature qw(say);
use autodie;
use Net::SFTP::Foreign;
# US Server Configuration
use constant {
HOST => "Server_Name",
REMOTE_DIR => "\\",
LOCAL_DIR => "sample/local",
PORT => "3235",
USER_NAME => "name",
PASSWORD => "password",
BACKEND => "Net_SSH2",
DEBUG => "0",
};
my $stfp = Net::SFTP::Foreign->new (
HOST,
backend => BACKEND,
timeout => 240,
user => USER_NAME,
password => PASSWORD,
port => PORT,
autodie => 1,
);
#
# List remote directory contents
#
my $remotefiles;
$remotefiles = $stfp->ls(REMOTE_DIR);
#
# Loop through remote files and print each filename
#
foreach ($remotefiles){
my $file = $_;
my $filename = $file->{filename};
if($filename ne "." && $filename ne ".."){
print"the filename is $filename";
}
}
$stfp->disconnect;
我收到以下错误 - 此行不是 HASH 引用 -> my $filename = $file->{filename};
不确定问题是什么或如何解决。