Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to list directory in Net::SFTP

Posted on 2011-02-17
8
Medium Priority
?
1,246 Views
Last Modified: 2012-05-11


The dir is not echo'ed to stdout
# Make connection
$sftp = Net::SFTP->new($address, %args);
$sftp->ls('/tmp');
print "Finished\n";
exit;
0
Comment
Question by:MatthewF
  • 5
  • 3
8 Comments
 
LVL 14

Expert Comment

by:svgmuc
ID: 34915777
This will read the list of files into an array:

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

You can output that with normal print statements.
0
 

Author Comment

by:MatthewF
ID: 34915820

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

Undefined subroutine &main::ls called at ./sftp.pl line 16.
0
 
LVL 14

Expert Comment

by:svgmuc
ID: 34915998
Oh, sorry, that was a typo...

@listing = $sftp->ls('/tmp');
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:MatthewF
ID: 34916041
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
 
LVL 14

Accepted Solution

by:
svgmuc earned 1200 total points
ID: 34916542
Then it has changed... try %listing instead of @listing

@listing = $sftp->ls('/tmp');
while ( my ($key, $value) = each(%listing) ) {
        print "$key => $value\n";
}
0
 

Author Comment

by:MatthewF
ID: 34916787
nothing is printed and there are files in /tmp
0
 

Author Comment

by:MatthewF
ID: 34916811
this worked

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

0
 

Author Closing Comment

by:MatthewF
ID: 35190476
With his help I was able to gigure out the answer
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question