Help deciphering FTP get perl script

I found this very useful perl script that will check a remote ftp server, search for files of a specific time and get them. When I run the script it works, but it gave me the following error:

Couldn't get filename_12-13-07.txt Bad file number

What in this script would cause this? I know nothing about perl.

#!/usr/bin/perl
use Net::FTP;
$date=shift @ARGV;
@months=qw(null Jan Feb Mar Apr My Jun Jul Aug Sep Oct Nov Dec);
@hosts=qw(ftp.server.com);
@dirs=qw(/);
@logins=qw(username);
@passwords=qw(password);

$x=0;
foreach(@months) {
$months{$_}=$x++;
}
# we need this hash later

if (not $date) {
$now=time();
$now -= (24 * 3600 );
# yesterday
($nowsec,$nowmin,$nowhr,$nowday,$nowmon,$nowyr,$nowdow,$nowdoy,$nowdst)=localtime($now);
$nowyr+=1900;$nowmon++;
$date=sprintf("%.2d/%.2d/%.4d",$nowmon,$nowday,$nowyr);
print "Using $date\n";
}

$now=time();
($nowsec,$nowmin,$nowhr,$nowday,$nowmon,$nowyr,$nowdow,$nowdoy,$nowdst)=localtime($now);
$nowyr+=1900;

# need $nowyr later

($month,$day,$year)=split /\//,$date;

#
# broken next century - blame me then
#
$year+=2000 if $year < 100;

$x=0;
foreach (@hosts) {
$newerr=0;
$ftp=Net::FTP->new($,Timeout=>240) or $newerr=1;
push @ERRORS, "Can't ftp to $
: $!\n" if $newerr;
next if $newerr;
print "Connected $_\n";

$ftp->login($logins[$x],$passwords[$x]) or $newerr=1;
push @ERRORS, "Can't login to $: $!\n" if $newerr;
$ftp->quit if $newerr;
next if $newerr;
print "Logged in $
\n";

$ftp->cwd($dirs[$x]) or $newerr=1;
push @ERRORS, "Can't cd $dirs[$x] on $_ $!\n" if $newerr;
$ftp->quit if $newerr;
next if $newerr;
print "Getting file list $_\n";

@files=$ftp->dir or $newerr=1;
push @ERRORS, "Can't get file list on $_ $!\n" if $newerr;
$ftp->quit if $newerr;
next if $newerr;
print "Got list $_\n";

print "Looking for $date $time\n";
foreach(@files) {
$_=substr($_,41);
s/ */ /g;
s/^ *//g;
chomp;
@stuff=split / /;
# if it's today, the year slot will have time instead
# so make it this year
$stuff[2]=$nowyr if /:/;

  $ftp-&gt;quit if \($stuff[2] &lt; $year\); 
  next if \($stuff[2] &lt; $year\); 
  $ftp-&gt;quit if \($months\{$stuff[0]\} &lt; $month and $stuff[2] == $year\); 
  next if \($months\{$stuff[0]\} &lt; $month and $stuff[2] == $year\); 
  $ftp-&gt;quit if \($stuff[0] &lt; $day and $stuff[2] == $year and $months\{$stuff[0]\} == $month\); 
  next if \($stuff[1] &lt; $day and $stuff[2] == $year and $months\{$stuff[0]\} == $month\); 



print "Getting $_\\n"; 
$ftp-&gt;get\($stuff[3],$stuff[3]\) or $newerr=1; 
  push @ERRORS, "Couldn't get $stuff[3] $!\\n" if $newerr; 

}

$ftp->quit;
}

print @ERRORS;
exit 0;

This looks like an error from the ftpd to me.
What happens if you manually try to ftp over and get that file?

You're right I guess it was an error. I tried to run the script again and I'm getting just looking for 1/22/08. This is not what I need. I need a script that will:

  1. Connect and Log into a remote FTP Server
  2. Look for the latest file called "This_Sample_File_01-22-08.txt"
  3. Change directories on my local box to /this/dir/for/file This_Sample_File_01-22-08.txt
  4. Get the file "This_Sample_File_01-22-08.txt"
  5. Close the connection.