Question : FTP script to get bin files from Unix server, after 1st file error "Bad file descriptor"  rest files also error but all files can be manually pulled by mget at DOS-prompt.

Sirs,

We have an Automated FTP script that pulls file from a server. This Script sometimes works without any error but sometimes is unable to pull even a single file. In case of such error, we manually (from DOS prompt) connect(FTP) to Unix based server and get files through "mget" command. This means that network and files are proper, but why is the script unable to pull with first error_msg as "Bad file descriptor" and all the other files give error_msg as "No such file or directory".

The relevent portions of the script are below:
===============================
####Connect to Server
open (FD1, ">>$logname") || print FD1 "Couldnt open - write $logname\n" ;
my $ftp=new Net::FTP("$server",Timeout=>"300000")|| print FD1 "Can not connect to ftp server\n";
$ftp->login("$username","$passwd")|| print FD1 "Can not login to ftp server\n";
.....
......

my @files=$ftp->dir or print FD1 "error in dir list--to var-- $dir \n";
....
.....
foreach(@files) {
#print "$_\n";
$_=substr($_,41);
s/ */ /g;
s/^ *//g;
chomp;

print FD1 "Getting $_\n";
$filename2=$_;
$filename=substr($filename2,0,12) ;
....
...
if( -f $first_check)
{
print FD1 "$filename exist, So no need to download \n";
}
else
{
.....
$ftp->binary();
$ftp->get($filename2) or $newerr=1;
#|| print "$filename2 can not be downloaded error $!\n";
if ($newerr)
{
print FD1 "$filename2 can not be downloaded error $!\n";
}
else {
print FD1 "Got file $filename2 \n";
......
.....
}
}
=============================

The relevent Log file output is below:

============================
TTFILE008498 exist, So no need to download
Getting TTFILE008499;1
TTFILE008499 exist, So no need to download
Getting TTFILE008500;1
TTFILE008500;1 can not be downloaded error Bad file descriptor
Getting TTFILE008501;1
TTFILE008501;1 can not be downloaded error No such file or directory
Getting TTFILE008502;1
TTFILE008502;1 can not be downloaded error No such file or directory
================================

Here the file that needs to be downloaded should not exists (first_check), and then download in binary mode.
We are unable to pull a single file somtimes, but n/w and file are fine.

Please suggest.

Ritu Nigam.

Answer : FTP script to get bin files from Unix server, after 1st file error "Bad file descriptor"  rest files also error but all files can be manually pulled by mget at DOS-prompt.

I don't have any experience with those systems or languages. I suppose we could guess that whatever problems arise from an unknown incompatibility between the Perl::FTP module and the FTP implementation on the target system -- but I don't think that's likely. More likely, to my mind, is that the manipulations you perform on the results of $ftp->dir to get filenames that you pass to $ftp->get is sometimes getting the filename wrong -- maybe if you had more debugging statements, we could better see what is happening.
Random Solutions  
 
programming4us programming4us