• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 739
  • Last Modified:

Case insensitive in Perl while doing FTP.

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
sventhan
Asked:
sventhan
1 Solution
 
Adam314Commented:
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
 
sventhanAuthor Commented:
super ! Fantastic!

Thanks again.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now