sachin raj aryan has asked for the wisdom of the Perl Monks concerning the following question:

I AM TRYING TO DOWNLOAD FILES AND AND DIRETORIES,SUBDIRETORIES FROM FTP SERVER. IT IS NOT DOWNLOADING DIRECTORIES ,SUBDIRECTORIES AND CONVERTING .GZ FILES TO .TXT WHICHEVER FILES IT BROUGHT FROM REMOTE SERVER FROM FIRST LEVEL DIRECTORY. FOR REST IT IS GIVING SAME ERROR.

use Net::SFTP::Recursive qw(:all); use IO::Uncompress::Gunzip qw(gunzip $GunzipError); use Date::Simple qw(d8); use DBI; use DBIx::Dump; use Time::Piece; use Time::Seconds 'ONE_DAY'; my $host = "10.31.0.35"; my $user = "lho"; my $password = "lho"; my $basedir = "locations"; my$reportfldr = "reports"; my $reportdr ="Reports_On_Request"; my $filename = 'branchList1tst.txt'; $date = $ARGV[0]; # date is your first argument{ FORMAT + (20161125)}#### uncomment this line and enter date while running s +cript if #you want to manually fetch report and commnet below +block #autodate # my $out = qx(net time); #toget current date # my @sachin = split/\s+/,$out; #toget current date aut +odate # print "$sachin[5] \n"; #toget current date autodate # my @datesys = split/-/,$sachin[5]; #toget current date auto +date # my $dt_column = join ("",$datesys[2],$datesys[1],$datesys[0]); #toge +t current date autodate # $date =$dt_column; #toget current date autodate # my $yesterday= (localtime() -ONE_DAY)->ymd(''); #autodate # print "$yesterday \n"; #autodate # $date = $yesterday; #autodate #Starting of Main Program # my $d = d8($date); my $error_log=$d-> format ('%d/%b/%Y'); #my $brchid="b00330"; ####brchid it is reading from branchList file +##### open (STDERR,">",$error_log) ; ############Fetching report from LHO Server########################### +############# open(my $fh, '<:encoding(UTF-8)', $filename)or die "Could not open fi +le '$filename' $!"; while ( my $line = <$fh>) { chomp $line; my @splitline=split/[|]/,$line; my $brid = $splitline[0]; my $regn = $splitline[1]; print "Starting $branchname\t"; $brnchid = substr $brchid,1 ; print "$brnchid upload \n"; system "mkdir $brchid"; chdir($brchid); my $dir = join"/",$basedir,$brchid,$reportfldr,$date; print "$dir"; print " FTP is ongoing in main file \n"; my %args =( user =>'lho',password=>'lho',port=>22,debug=>2); my $f = Net::SFTP::Recursive->new($host,%args); $f->status; $f->ls($dir,sub {print $_[0]->{filename},"\n"}); $f->rget($dir,'E:\fastscript\reports trasnfer\tmp'); #$f->exit; print " FTP done \n"; close ($fh); }

Logs are as under

I03977DE207: sftp: Sent message T:11 I:14221 Couldn't get handle: Bad message at E:\fastscript\reports trasnfer\rep +orts.pl line 80. + making local dir E:\fastscript\reports trasnfer\tmp/../././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././../../../NFT_00317_27092019_27092 +019191651_952.TXT... + from locations/b06066/reports/20191225/../././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/./././././././././././../../../NFT_00317_27092019_27092019191651_952 +.TXT to E:\fastscript\reports trasnfer\tmp/../././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././././././././././././././././././././././././. +/././././././././././././././././././././././././././././././././././ +././././././././././././../../../NFT_00317_27092019_27092019191651_95 +2.TXT... I03977DE207: sftp: Sent message T:11 I:14222 Couldn't get handle: Bad message at E:\fastscript\reports trasnfer\rep +orts.pl line 80. FN: l LN: -rw-r--r-- 1 cdc branches 0 Mar 21 2018 l

Replies are listed 'Best First'.
Re: Net::SFTP::Recursive not downloading files recuresively
by salva (Canon) on Dec 30, 2019 at 15:07 UTC

      can't use foreign as it won't allow to enter password

Re: Net::SFTP::Recursive not downloading files recuresively
by soonix (Chancellor) on Dec 30, 2019 at 13:07 UTC
    I know nothing about Net::SFTP::Recursive, but I'd say a folder name containing multiple "/./." and ending in NFT_0­0317_27092019_27092019191651_952.TXT is suspicious. Probably the module doesn't understand some message from your server.

    Last change of the module is 2005. This is normally not a bad sign, but the SSH protocols have undergone several updates, so you might better look for something newer, even though you'd have to implement the directory recursion yourself when resorting to Net::SFTP or Net::SSH2::SFTP.

Re: Net::SFTP::Recursive not downloading files recuresively
by Anonymous Monk on Dec 30, 2019 at 12:42 UTC