Solved

Case insensitive in Perl while doing FTP.

Posted on 2008-09-29
2
724 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
remove duplicates from the csv file 13 122
add a syntax to a csv file 8 101
read an xml file in perl 2 85
octal error in perl program 3 42
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…

732 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