#!/usr/bin/perl use strict; use warnings; use Net::SFTP::Foreign; my %args = ( user => 'user', password => 'password', more => '-v', autodisconnect => 0 ); my $sftp = Net::SFTP::Foreign ->new('localhost', %args); $sftp->error and die $sftp->error; $sftp->status or $sftp->error; my $ls = $sftp->ls('/root') or die "Unable to retrieve directory: " . $sftp->error; print "$_->{filename}\n" for (@$ls); $sftp->disconnect;