Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

how to list directory in Net::SFTP

Posted on 2011-02-17
8
1,230 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 

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 400 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…

856 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