Solved

Case insensitive in Perl while doing FTP.

Posted on 2008-09-29
2
709 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now