#!/opt/local/perl/bin/perl -w use strict; use Net::SFTP; my $sftp = Net::SFTP->new("serverURL.com", user => "myUser", password => 'myPassword', debug => 1); my $targetDir = "/ftp/pub"; # connection dropped at this line when run from cron, but not from command line my $lsHashRef = $sftp->ls($targetDir); map { my $filename = $_->{filename}; print "$filename\n"; } sort {$a->{filename} cmp $b->{filename}} @$lsHashRef; print "Done!\n";