By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,541 Members | 1,455 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,541 IT Pros & Developers. It's quick & easy.

FTP Uploading problem in perl scripts

P: 3
Hi All,

I have problem while uploading files to remote FTP using perl scripts if the size is high, also FTP session is cut . Can any one suggest me how to overcome this issue?.

Regards
Jayaram
Nov 7 '08 #1
Share this Question
Share on Google+
2 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
Can you please provide more information? We need to see a log file or the output of what is happening so that we can help you. Also, can you please post your script (enclosed in code tags)?

Thanks!

Jeff
Nov 7 '08 #2

P: 3
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
Nov 10 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.