hi
I need help, to change this perl script.
I get many times a day 3 TEXT files:
one info file and two data files.
info file looks:
---------------------------------
FA12300011 TN20040203
GA12300012 TT20040203
----------------------------------
this perl script first opens and reads the info file,
renames the first file FA12300011 to TN20040203,
sends via ftp the first file,
waits 15 minutes,
renames the second file GA12300012 to TT20040203
and sends via ftp.
the name of the info file never changed,
but names of these 2 data files YES.
how to change this script ,to check if file names are the same like on the info file ?
otherwise should stop the whole process and not transfer any files.
should have 2 date files and one info file each time.
I need help, to change this perl script.
I get many times a day 3 TEXT files:
one info file and two data files.
info file looks:
---------------------------------
FA12300011 TN20040203
GA12300012 TT20040203
----------------------------------
this perl script first opens and reads the info file,
renames the first file FA12300011 to TN20040203,
sends via ftp the first file,
waits 15 minutes,
renames the second file GA12300012 to TT20040203
and sends via ftp.
the name of the info file never changed,
but names of these 2 data files YES.
how to change this script ,to check if file names are the same like on the info file ?
otherwise should stop the whole process and not transfer any files.
should have 2 date files and one info file each time.
Code:
#!/usr/bin/perl -w
use strict;
use warnings;
use Net::FTP;
# change directory
chdir "/ftp/files" or die "/ftp/files: $!\n";
# DO NOT transfer without info file
-f "/ftp/files/info" or die "info file is missing\n";
open(FILE, "<info>");
my $cwd_performed = 0;
while (<FILE> ) {
s/\W*$//;
next if (!$_);
/^(.+?) \s+ (.+?)$/x;
my ($old, $new) = ($1, $2);
rename $old, $new;
# ftp transfer
my $server = "X.X.X.X";
my $ftp = Net::FTP->new ($server, Timeout => 9000, Debug => 3);
$ftp or die "$server: cannot connect: $@";
# If you don't use ~/.netrc
$ftp->login ('anonymous', 'mail@adress') or
die "$_: cannot logon: " . $ftp->message;
# change remote directories
if ($cwd_performed >0) {
$ftp->cwd("FTP/IN2")
}
else {
$ftp->cwd("FTP/IN1") if (!$cwd_performed++)
}
# Put first file to the ftp server
$ftp->put ($2) or
die "$server: cannot put $2: " . $ftp->message;
$ftp->quit;
sleep (15 * 60)
}