use warnings; use strict; use Net::SFTP::Foreign; my $host = 'localhost'; my $list_file = 'files.txt'; my $sftp = Net::SFTP::Foreign->new($host); # look in my scratch working directory my @list = $sftp->find('scratch'); open my $wfh, '>', $list_file or die $!; print $wfh "$_->{filename}\n" for @list;