473,395 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

FTP Uploading problem in perl scripts

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
2 3084
numberwhun
3,509 Expert Mod 2GB
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
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

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

Similar topics

2
by: Sandman | last post by:
The subject says it all. I am doing a: I have a perl script in which I am using a ReadParse routine that parses the $ENV{'QUERY_STRING'} or $ENV{'CONTENT_LENGTH'} which are two variables passed...
42
by: Fred Ma | last post by:
Hello, This is not a troll posting, and I've refrained from asking because I've seen similar threads get all nitter-nattery. But I really want to make a decision on how best to invest my time....
2
by: noone | last post by:
Hello all, I am absolutely brand new to perl, but I understand that it is a very important aspect of web development to create dynamic web pages. I am kind of short on money, being a college...
1
by: Al Belden | last post by:
Hi all, I've been working on a problem that I thought might be of interest: I'm trying to replace some korn shell scripts that search source code files with perl scripts to gain certain features...
0
by: Kirt Loki Dankmyer | last post by:
So, I download the latest "stable" tar for perl (5.8.7) and try to compile it on the Solaris 8 (SPARC) box that I administrate. I try all sorts of different switches, but I can't get it to compile....
12
by: rurpy | last post by:
Is there an effcient way (more so than cgi) of using Python with Microsoft IIS? Something equivalent to Perl-ISAPI?
0
by: TCook | last post by:
Hello All, I was wondering 2 things: 1) How to enable PERL CGI scripts with ASP.Net? I have ActivePerl installed but the CGI scripts that I have do not seem to run. I get missing header...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.