Solved

how to list directory in Net::SFTP

Posted on 2011-02-17
8
1,226 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now