It has been awhile since I have used perl and I am attempting to print out a list of files on a SFTP server.
This is my Perl script -
#! /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;
I am getting the following error - Not a HASH reference at this line -> my $filename = $file->{filename};
Not sure what the problem is or how to fix it.