in reply to Error with Net::SFTP:Foreign

It seems to me that you are connecting to one host, then that connection is disconnected before the next host is called; hence you get "connect from the command line first". One possible solution would be to add the autodisconnect option to %args. For example, here's what I tried:
#!/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;