Hi,
I am trying to download files using Net::FTP perl module. I am facing problem with downloaded files not able to place in there respective folders. Please need help, I am providing the code below

#!/usr/bin/perl

use Net::FTP;
use File::Copy;

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

$ftp->login("anonymous",'-anonymous@')
or die "Cannot login ", $ftp->message;

open(FH,"Organism_list.txt");

@organism_name="";
@ftp_id="";

while(<FH>)

{

chomp($);
@records=split("\t",$
);

push(@organism_name,$records[0]);
push(@ftp_id,$records[1]);

 }



$len=@organism_name;

@ext=("ptt","rnt");

for($i=0;$i<$len;$i++){

$path="/genomes/Bacteria/$ftp_id[$i]/*.";

mkdir("$organism_name[$i]");

@org="";

my $directory="E://projects";

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

foreach $data(@ext)

{



  $retrive=$path.$data;
  @files=$ftp->dir($retrive);

  foreach (@files)
  {

if(/.*(\/genomes.*\.$data)/)
{
    print $1,"\n";

    push(@org,$1);

}

$ftp->get($1);

  }}}

close FH;

Thanking you,
Rajesh

Hi rajesh9042,

There are several things not right with your script namely:

  1. Please start your script with use warnings and use strict pragmas, though I know many people may not like these. But believe me, those are your best friend programming in Perl,

  2. What do you have in your "Oragnism.txt"? Since, we would not loop through all the files in the ftp, what are the identity of the folder and file one is looking for,

  3. In your while loop, you can't chomp "$", you chomp $_. If either you write chomp; only by itself, since it default variable is $_ or you expicitily write chomp $_;.

What error messages are you receiving when you run the script?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.