use Net::FTP;
$catalog=$ARGV[0] ; # e.g. %area%
$sqluser=$ARGV[1] ; # oracle connection string; user/user@user
#$sqluser="%area%" ;
$ftp_adr=$ARGV[2] ; # ftp server, ip adress
$ftp_user=$ARGV[3];
$ftp_pwd=$ARGV[4] ;
$loggfile="$catalog/proc/ftplog.$$" ;
$programname="EDL400BA" ;
$local_dir="%area%";
$read_catalog=$katalog . "/%area%" ;
chdir $catalog . "/" . $local_dir || die "could not cwd to $katalog . "/" . $local_dir \n";
$ftp = Net::FTP->new($ftp_adr, Debug => 0) or die "Can't start ftp\n";
$ftp->login($ftp_user,$ftp_pwd) or die "Login error: $ftp_user/$ftp_pwd";
$filecount=0;
foreach $file ($ftp->ls) {
if ($file =~ /^e.*/ ) {
$ftp->get($file) or die "Can't get the file $file\n";
$filecount++;
$cmd = "perl $catalog/script/load_edl400ba.pl $catalog $sqluser $file";
if ( system($cmd) == 0 ) {
$ftp->delete($file) or print "Couldn't delete the file: $file\n";
}
else {die "Error loading file: $file - ending.\n"};
rename $catalog . "/" . $local_dir . "/" . $file, $read_catalog . "/" . $file;
}
}
$ftp->quit || print "Error closing ftp (ignored)\n";
print "$filecount file(s) grabbed from the server $ftp_adr\n";