Hi all,
Let me first start out by saying I'm a
perl newbie and hope somebody can help, for the life of me I can't figure out why my script will not find and download a remote file via FTPSSL. What it's supposed to do is find the latest file named simple-test-case_
("dd-MM-yyyy-hh-mm-ss").csv i.e.
Quote:
|
simple-test-case_09-01-2009-08-17-51.csv
|
and download it. But when I run it (no error or warnings) it acts like it does not find the file and hence not download it. A second pair of eyes and guidance would be much appreciated. I personally feel it's my regex.
Code:
use strict;
use warnings;
use Net::FTPSSL;
use Getopt::Long qw(:config no_ignore_case);
my $hostname = '127.0.0.1';
my $username = 'testuser';
my $password = 'testpass';
my $port = '21';
my $directory = '/';
my $verbose = '1';
my $passive = '0';
my $timeout = "30";
my $version = "0.0.2";
my $input_dir = "input";
my $output_dir = "output";
my $input_trg_file = "simple-test-case.csv";
my $input_csv_file = "simple-test-case.trg";
#Bellow var will be used later
my $output_file = "simple-test-case*.csv";
#
my $encryption = "E";
# creating connection and starting the test
my $ftps = Net::FTPSSL->new($hostname, Debug => $verbose, Port => $port, Encryption => $encryption ) or die "ERROR: Cannot conect to $hostname\n";
if (!$ftps->login("$username","$password")) {
print "ERROR: Sever says: ", $ftps->last_message;
exit 2;
}
if ($input_trg_file eq "") {
if (!$ftps->list("$directory")) {
print "WARNING: server says: " , $ftps->last_message;
exit 1;
} else {
print $ftps->last_message;
}
} else {
if (!$ftps->cwd("/$input_dir")) {
print "WARNING: server says: " , $ftps->last_message;
exit 1;
} else {
if (!$ftps->put("$input_trg_file","/$input_dir/$input_trg_file")) {
print "WARNING: server says: " , $ftps->last_message;
exit 1;
} else {
if (!$ftps->put("$input_csv_file","/$input_dir/$input_csv_file")) {
print "WARNING: server says: " , $ftps->last_message;
exit 1;
} else {
if (!$ftps->cwd("/$output_dir")) {
print "WARNING: server says: " , $ftps->last_message;
exit 1;
} else {
sleep(10);
my @lines = grep { /^simple-test-case./i } $ftps->list();
foreach my $name (@lines) {
if (!$ftps->get("$name, /tmp/$name")) {
print "WARNING: server says: " , $ftps->last_message;
} else {
my @message = $ftps->last_message;
chomp @message;
print "OK: ", "$message[0] $message[1]\n";
exit 0;
}
}
}
}
}
}
}
$ftps->quit;
Thanks in advance,
Eric