Solved

how to list directory in Net::SFTP

Posted on 2011-02-17
8
1,228 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

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 …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

786 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