You must put the FTP transmission into binary mode (just call the binary 
method before the get).

HTH,

ken1

----- Original Message ----- 
From: neeti somaiya
To: [email protected]
Sent: Friday, November 24, 2006 6:12 AM
Subject: Need help in Net::FTP module


Hi,

I am using the Net::FTP module of Perl to download files from NCBI ftp. 
These are .gz files. When I download these files by normally doing a ftp 
login through command-line, I am able to successfully download these files 
and later gzip -d (i.e. uncompress) them. But when I do it via a perl 
program using the Net::FTP module and the exact same steps as that through 
the command-line, the download returns success, but the file size is a 
little less than the actual size and when I try to decompress it, it gives 
me an error. An example is a file zebrafish.rna.gbff.gz available on the ftp 
site ftp://ftp.ncbi.nih.gov/refseq/D_rerio/mRNA_Prot/. When I downloaded it 
through command-line ftp login the size is 50448748, which is the correct 
size as can be seen on the ftp site also, and I am able to successfully 
decompress it. But when I do it via my program, the size of the same file is 
50448049, which is a little less than the correct size and decompressing it 
gives an error, but the ftp download returns that it was all successfully 
donwloaded.

My code is as follows :-

use Net::FTP;

my  $ftp = Net::FTP->new("ftp.ncbi.nih.gov", Debug => 0)
or die "Cannot connect to ncbi ftp site";

print "Connected to ncbi ftp site\n";

$ftp->login("anonymous",'xyz')
or die "Cannot login into ncbi ftp site", $ftp->message;

print "Ncbi ftp login done\n";

$ftp->cwd(refseq)
or die "Cannot change working directory", $ftp->message;

print "Working directory changed to refseq\n";

my @organisms = ('D_rerio');

my @commonnames = ('zebrafish');

my $index = -1;

# loop for all organisms

foreach my $org (@organisms)
{

# incrementing index to get values from arrays
$index++;

$ftp->cwd($org)
or die "Cannot change working directory", $ftp->message;

print "Working directory changed to $org\n";

my $data_dir = "mRNA_Prot";
$ftp->cwd($data_dir)
or die "Cannot change working directory", $ftp->message;

print "Working directory changed to mRNA_Prot\n";

my $mrna_data_file = $commonnames[$index].".rna.gbff.gz";

my $return = $ftp->get($mrna_data_file)
or die "get failed for $mrna_data_file", $ftp->message;

if (defined($return))
{
print "\n***************$return\n";
print  "$mrna_data_file downloaded\n";
}
else
{
  print "there was problem downloading $mrna_data_file\n";
}

$ftp->cdup();

$ftp->cdup();

undef $data_dir;

undef $mrna_data_file;

}# for each organism


Can someone please help me in figuring out what could be going wrong.



-- 
-Neeti
Even my blood says, B positive



_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs 

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to