Solved

Case insensitive in Perl while doing FTP.

Posted on 2008-09-29
2
705 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
Comment Utility
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
Comment Utility
super ! Fantastic!

Thanks again.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

771 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

10 Experts available now in Live!

Get 1:1 Help Now