Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
XP is just a number
 
PerlMonks  

pattern matching with wildcards...

by mikerzz (Acolyte)
on May 12, 2009 at 15:52 UTC ( #763515=perlquestion: print w/ replies, xml ) Need Help??
mikerzz has asked for the wisdom of the Perl Monks concerning the following question:

MONKS! I am in need of assistance. Here is my problem. I have to log onto a server using ftp and retrieve only certain files from that server. There are about 40 different file patterns I have to search for and download via ftp. An example of the type of pattern is: CWCG0507.M.00047843.gz. All of the files share the .M. and the .gz extension, and that's about all they have in common. So I have to search for files where the field before the first "." varies. For example, these are just two of the approximately 30 extensions I need to search for: DVD.*M.*gz YDD.*M.*gz So my question is, how do I get a listing of all of the *.gz files on the ftp server and then search for just the patterns that I need to match? This has been driving me crazy for several days now. Thanks. Mike R

Comment on pattern matching with wildcards...
Re: pattern matching with wildcards...
by CountZero (Chancellor) on May 12, 2009 at 16:07 UTC
    Net::FTP::Common has a grep method which allows you to filter the files you need.

    Net::FTP::Simple can do

    my @received_filtered_files = Net::FTP::Simple->retrieve_files({ username => $username, password => $password, server => $server, remote_dir => 'path/to/dir', debug_ftp => 1, file_filter => qr/^ba.\.txt/, delete_after => 0, });
    which is even easier and uses the full power or perl-regexen.

    Update: added the example from the Net::FTP::Simple-documentation.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      CountZero, Thanks for the response. I probably should have mentioned that I can't install any other Perl modules on this server, so I am stuck using only Net::FTP. Mike R
        Net::FTP::Simple is pure Perl, so if the server-admins refuse (for no good reason) to install it, you can still include it in your own home-folder or even as part of your own script.

        Have a look at Yes, even you can use CPAN.

        CountZero

        A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://763515]
Approved by AnomalousMonk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (11)
As of 2014-04-18 09:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (465 votes), past polls