how to list directory in Net::SFTP



The dir is not echo'ed to stdout
# Make connection
$sftp = Net::SFTP->new($address, %args);
$sftp->ls('/tmp');
print "Finished\n";
exit;
MatthewFAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
svgmucConnect With a Mentor Commented:
Then it has changed... try %listing instead of @listing

@listing = $sftp->ls('/tmp');
while ( my ($key, $value) = each(%listing) ) {
        print "$key => $value\n";
}
0
 
svgmucCommented:
This will read the list of files into an array:

@listing = $sftp=>ls('/tmp');

You can output that with normal print statements.
0
 
MatthewFAuthor Commented:

16  @listing=$sftp=>ls('/tmp');

Undefined subroutine &main::ls called at ./sftp.pl line 16.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
svgmucCommented:
Oh, sorry, that was a typo...

@listing = $sftp->ls('/tmp');
0
 
MatthewFAuthor Commented:
that prints out the HASH value

HASH(0xfa4cbc) HASH(0xfa4d58) HASH(0xfa4da0) HASH(0xfa4e48) HASH(0xfa4ef0) HASH(0xfa4f98) HASH(0xfa5040) HASH(0xfa50e8) HASH(0xfa5190) HASH(0xfa5238) HASH(0xfa52e0) HASH(0xfa5388) HASH(0xfa5430) HASH(0xfa54d8) HASH(0xfa5580) HASH(0xfd4f6c) HASH(0xfd5014) HASH(0xfd50bc) HASH(0xfd5164) HASH(0xfd520c) HASH(0xfd52b4) HASH(0xfd535c) HASH(0xfd5404) HASH(0xfd54ac) HASH(0xfd5554) HASH(0xfd55fc) HASH(0xfd56a4) HASH(0xfd574c) HASH(0xfd57f4) HASH(0xfd589c) HASH(0xfd5944) HASH(0xfd59ec) HASH(0xfd5a94) HASH(0xfd5b3c) HASH(0xfd5be4) HASH(0xfd5c8c) HASH(0xfd5d34) HASH(0xfd5ddc) HASH(0xfd5e84) HASH(0xfd9930) HASH(0xfd99d8) HASH(0xfd9a80) HASH(0xfd9b28) HASH(0xfd9bd0) HASH(0xfd9c78) HASH(0xfd9d20) HASH(0xfd9dc8) HASH(0xfd9e70) HASH(0xfd9f18)
0
 
MatthewFAuthor Commented:
nothing is printed and there are files in /tmp
0
 
MatthewFAuthor Commented:
this worked

$sftp->ls("." , sub { print $_[0]->{longname}, "\n" });

0
 
MatthewFAuthor Commented:
With his help I was able to gigure out the answer
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.