Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

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

by ssubrat77 (Novice)
on Jun 03, 2011 at 05:51 UTC ( #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 => '', 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 (Abbot) 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 (Chaplain) 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, 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://907911]
Approved by salva
Front-paged by toolic
[Corion]: Hmm - "trust" sounds interesting, but I have still to find whether I can restrict that on a per-DB level ;)
[Corion]: erix: Sure, but SQLite doesn't even need that :)
[hippo]: Corion: Yes, you can. It's all in the pg_hba.conf
[erix]: yeah, but there is a lot SQLite cannot do :)
[hippo]: Database is the 2nd column.
shmem .oO( docker. docker. docker? docker. docker! docker )
[shmem]: at least, some Ook.
[erix]: another simple Pg thing is to running a database off a tsv (alas, readonly)
[erix]: I'm waiting for that zipfile-reading to show up in DBD::SQLite :)
[Corion]: hippo, erix: That sounds promising :)

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (14)
As of 2018-02-23 15:14 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (302 votes). Check out past polls.