Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Net::SFTP::Foreign hwo to list (ls) files

by ssubrat77 (Novice)
on Jun 03, 2011 at 05:51 UTC ( [id://907911]=perlquestion: print w/replies, xml ) Need Help??

ssubrat77 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, Need your expert advise to fix one urgent issue. I want to list all the files in SFTP remote server which satisfy the particular pattren like we do ls abcd*.txt. I treid to use the bleow code but not working. Please help
use Net::SFTP::Foreign; my $sftp = Net::SFTP::Foreign->new( host => 'myserver.com', port => '22', user => 'ftpuser', more => [qw( -i myserver.private.key.ppk)], ssh_cmd => 'plink'); $sftp->die_on_error("Unable to establish SFTP connection"); my $entry = "abcd*.txt"; my $files = $sftp->ls ('/etc', wanted => qr/$entry/) or die "unable to + retrive directory: ".$sftp->error;
-- Thanks for all the replies. My problem got resolved. Thanks a lot for your help

Replies are listed 'Best First'.
Re: Net::SFTP::Foreign hwo to list (ls) files
by salva (Canon) on Jun 03, 2011 at 07:27 UTC
    The mget method does what you want:
    $sftp->mget("/etc/abcd*.txt", $local_dir);

    update: Oops, that would download the files. Use glob if you just want to list them:

    my $files = $sftp->glob("/etc/abcd*.txt");
    or maybe...
    my $files = $sftp->glob("/etc/abcd*.txt", names_only => 1);
Re: Net::SFTP::Foreign hwo to list (ls) files
by philipbailey (Curate) on Jun 03, 2011 at 07:07 UTC

    You don't say exactly what is not working. What is the output when you run your program?

    Given the title of your post, presumably the failure is in the directory listing. Looking at the documentation for Net:SFTP:Foreign.pm, the wanted value should be a full regex, not a glob-style expression. So perhaps you want a regex more like /^abcd.*\.txt$/ ? Your existing regex will find files matching "abc", followed by zero or more "d", followed by one character, followed by "txt".

    A couple of other customary comments: please enclose code in <code> tags. You can go ahead and edit your post now to do this. It's not advisable to say that your question is "urgent" as some of the monks do not like this, and might not encourage replies.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://907911]
Approved by salva
Front-paged by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (1)
As of 2024-04-24 15:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found