in reply to Modifying Script From Net::SFTP to Net::SFTP::Foreign

Not a HASH reference at /root/backup/backswitch.pl line 20.
foreach $i ($sftp->ls(".")){ $fname=$i->{filename};

As per the documentation, $sftp->ls returns a reference to a list, not a list.

Replies are listed 'Best First'.
Re^2: Modifying Script From Net::SFTP to Net::SFTP::Foreign
by salva (Canon) on Apr 10, 2019 at 21:10 UTC
    yes, ls returns a reference in order to be able to signal errors. The usual idiom for using it is as follows:
    my $ls = $sftp->ls(...) or die "ls failed: " . $sftp->error; for my $fn (@$ls) { ... }