Hi Jeff,
Pl find below the sample script
my $host = "172.16.1.258" ; ## testing server(FTP) details
my $user = "Ninestars" ;
my $pass = "0brette1ns" ;
my $projectname = "KIS-New";
my $uploadfile;
my $Title = "";
my @xmlfile = "";
print "Starting FTP at process $$ ($host)\nUploads .ZIP file to the KNIPSEL server\n";
my $destdir = "/Upload" ; ## Dest directory where the files be uploaded to, creates dir if does not exists
my $workdir = $ARGV[1];#existing
my $delete_sourcefile = -1 ; ## Do you want to delete the file after downloading it?
my $download_file = 1 ; ## Well, do you want to download?
our @ERRORS = () ;
my $newerr = 0 ;
my $fsize;
my $filenotpresent= 0;
my $FTPList = $ARGV[0];
chomp($FTPList);
$workdir =~ s/\\/\\\\/g;
chomp($workdir);
open(FTPLST,"$FTPList") || die "Unable to open the $FTPList file \n";
my $batchname;
#chomp($batchname);
#$destdir .= "$batchname\\";
#$backupdir .= "$batchname\\";
# MAKE A CONNECTION TO THE SERVER
my $ftp = Net::FTP->new($host,Timeout=>10) or $newerr=1;
push @ERRORS, "Can't ftp to host: $!\n" if $newerr;
myerr() if $newerr ;
# Login to the server
$ftp->login($user,$pass) or $newerr = 1;
push @ERRORS, $ftp->message if $newerr;
myerr() if $newerr;
print "Getting list of files \n";
#Set the transfer mode binary
$ftp -> binary ;
$ftp -> cwd("$destdir");
#$ftp -> cwd('$batchname');
#my $size = $ftp -> size ( $_ );
while(<FTPLST>)
{
chomp($_);
($batchname, $uploadfile) = split(",",$_);
$Title = (split("_",$uploadfile))[0];
$ftp -> cwd("$destdir");
# $ftp -> cwd($Publication{lc($Title)}); #CHANGE TO PUBLISHER DIR
if ( -f "$workdir\\$batchname\\$uploadfile.zip.tmp" ) {
print " Uploading ($uploadfile) \n";
$ftp -> put("$workdir\\$batchname\\$uploadfile.zip", $uploadfile.".zip") or $newerr=1;
push @ERRORS, $ftp->message if $newerr;
if ($newerr)
{
myerr();
$filenotpresent=1;
print "Error transferring the file $uploadfile";
<STDIN>;
}
else
{
print "Upload finished for $batchname\\$uploadfile @ $host \n";
if (! -d "$workdir\\$batchname")
{
mkdir("$workdir\\$batchname");
}
elsif ( ! -d "$workdir\\$batchname\\done")
{
mkdir("$workdir\\$batchname\\done");
}
rename("$workdir\\$batchname\\$uploadfile.zip", "$workdir\\$batchname\\done\\$uploadfile.zip") || print "unable to move the file to $workdir\\$batchname\\done directory \n";
print "File moved to $workdir\\$batchname\\done directory \n";
}
}
else
{
print "ZIP $workdir . $batchname . $uploadfile NOT transferred to KNIPSEL server. File not present\n";
$filenotpresent=1;
<STDIN>;
}
}
if ($filenotpresent == 1)
{
$newerr = $filenotpresent;
}
opendir(XMLLIST, "$workdir\\$batchname") || die "unable to open the directory\n";
my @xmlfile = grep /\.xml$/i,readdir(XMLLIST);
if ($#xmlfile >= 0)
{
foreach my $xmlfile (@xmlfile)
{
#print $xmlfile;<STDIN>;
$ftp -> put("$workdir\\$batchname\\$xmlfile",$xmlfile) or $newerr = 1;
rename("$workdir\\$batchname\\$xmlfile", "$workdir\\$batchname\\done\\$xmlfile") || print "unable to move the XML to $workdir\\$batchname\\done directory \n";
}
push @ERRORS, $ftp->message if $newerr;
if ($newerr)
{
myerr();
$filenotpresent=1;
print "Error transferring the file $uploadfile";
<STDIN>;
}
#print "XML PRESENT\n";<STDIN>;
}
$ftp->quit();
exit($newerr);
sub myerr
{
print "Error: \n";
print @ERRORS;
$newerr = 0;
exit 0;
}
I am facing problem while some zip file size is large and ftp session gets cut while uploading files to remote customer FTP.
Regards,
Jayaram