Solved

Case insensitive in Perl while doing FTP.

Posted on 2008-09-29
2
714 Views
Last Modified: 2012-06-21
I've to FTP few .txt files from the remote location and I've the following code to do it.

When I'm reading the remote files (only .txt) I want my perl script to be case insensitive that mean i want to read the file name ends with

.txt, .TXT, .Txt etc...


currently I'm the sub routing mget($ftp,'*.txt') only reading the small case .txt files from the remote location.

Please help.


  my $ftp = Net::FTP->new($server, Debug => 0) or die "Connect failed: $@\n";
  $ftp->login($userid, $password) or die "Login to the FTP server failed: ",$ftp->message,"\n";
  $ftp->ascii;
  $ftp->cwd($remotedir) or die "Failed to cd: $ftp->message\n";
      
  mget($ftp, '*.txt'); ## need to look for .TXT or .Txt




 sub mget {
    my ($ftp, $pattern) = @_;
    foreach my $file ($ftp->ls($pattern)) {
        $ftp->get($file)
        or warn $ftp->message;
    }
}


Thanks a lot.
0
Comment
Question by:sventhan
2 Comments
 
LVL 39

Accepted Solution

by:
Adam314 earned 500 total points
ID: 22599548
mget($ftp, '*.txt'); ## need to look for .TXT or .Txt
mget($ftp, '\.txt$'); ## need to look for .TXT or .Txt
 
sub mget {
    my ($ftp, $pattern) = @_;
    foreach my $file ($ftp->ls) {
        next unless $file =~ /$pattern/i;
        $ftp->get($file)
        or warn $ftp->message;
    }
}

Open in new window

0
 
LVL 18

Author Closing Comment

by:sventhan
ID: 31501313
super ! Fantastic!

Thanks again.
0

Featured Post

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.

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 …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

785 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