I am working on a perl script that will be used to connect to a ftp server and download a series of files. At this point, I have it working where it connects to the ftp server downloads the files and disconnects. However, there is one more thing I need to tag on to this. After I download all my idx data for the day, I need to download all the images for the day. The images come in a single zip file. The only issue I have is that in side of the img directory there are several days worth of image zip files. I only need to download the current day. The file name of the zip file looks something like this 07202007.zip. I know I can build a string based on the current date, but I would rather do it by datelastmodified. The only thing I can't figure out is how to access that data from the ftp method ls().
Here is my current code.
Code:
#!/usr/bin/perl -w
use Net::FTP;
my $host = $ARGV[0];
my $idxDir = $ARGV[1];
my $imgDir = $ARGV[2];
my $uName = $ARGV[3];
my $uPass = $ARGV[4]
#! Beging connection start
$ftp = Net::FTP->new("${host}", Debug => 0)
or die "Cannot connect to armlsidx.marketlinx.com: $@";
$ftp->login("${uName}",'${uPass}')
or die "Cannot login ", $ftp->message;
#! Change working directory to idx dir
$ftp->cwd("${idxDir}")
or die "Cannot change working directory ", $ftp->message;
#! Loop over idxDir and print file names
$ftp->ls("${idxDir}")
or die "ls failed ", $ftp->message;
foreach ($ftp->ls){
#!$ftp->get("$_","/mnt/homesmart-phx/mls/data/$_");
print("$_\n");
}
#! Change working directory img dir
$ftp->cwd("${imgDir}")
or die "Cannot change working directory ", $ftp->message;
#! Loop over imgDir and print file names
$ftp->ls("${imgDir}")
or die "ls failed ", $ftp->message;
foreach($ftp->ls){
print("$_\n");
}
#! Close FTP Connection
$ftp->quit;