From a04811425d84d19adabcb3df1c34eb4aca3610f2 Mon Sep 17 00:00:00 2001 From: Vasily Tokarev <34555288+tokarevvasily@users.noreply.github.com> Date: Tue, 26 Jan 2021 17:34:10 -0500 Subject: [PATCH] Refresh FTP connection for downloading libraries with `--use-ftp` I had issues with downloading genomes for *viral* library. I have noticed that it could download only first 92 genomes from *manifest.txt*. I am fairly certain that it is something NCBI implemented intentionally (or maybe not). I have made changes to *rsync_from_ncbi.pl* to refresh FTP connection if genome is not downloaded on the first attempt, otherwise it gives a warning. --- scripts/rsync_from_ncbi.pl | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/scripts/rsync_from_ncbi.pl b/scripts/rsync_from_ncbi.pl index 6ca239c..e4bb56d 100755 --- a/scripts/rsync_from_ncbi.pl +++ b/scripts/rsync_from_ncbi.pl @@ -79,16 +79,21 @@ close MANIFEST; } +sub ftp_connection { + my $ftp = Net::FTP->new($SERVER, Passive => 1) + or die "$PROG: FTP connection error: $@\n"; + $ftp->login($FTP_USER, $FTP_PASS) + or die "$PROG: FTP login error: " . $ftp->message() . "\n"; + $ftp->binary() + or die "$PROG: FTP binary mode error: " . $ftp->message() . "\n"; + $ftp->cwd($SERVER_PATH) + or die "$PROG: FTP CD error: " . $ftp->message() . "\n"; + return $ftp; + } + if ($use_ftp) { print STDERR "Step 1/2: Performing ftp file transfer of requested files\n"; - my $ftp = Net::FTP->new($SERVER, Passive => 1) - or die "$PROG: FTP connection error: $@\n"; - $ftp->login($FTP_USER, $FTP_PASS) - or die "$PROG: FTP login error: " . $ftp->message() . "\n"; - $ftp->binary() - or die "$PROG: FTP binary mode error: " . $ftp->message() . "\n"; - $ftp->cwd($SERVER_PATH) - or die "$PROG: FTP CD error: " . $ftp->message() . "\n"; + my $ftp = ftp_connection(); open MANIFEST, "<", "manifest.txt" or die "$PROG: can't open manifest: $!\n"; mkdir "all" or die "$PROG: can't create 'all' directory: $!\n"; @@ -99,7 +104,9 @@ or do { my $msg = $ftp->message(); if ($msg !~ /: No such file or directory$/) { - warn "$PROG: unable to download $_: $msg\n"; + $ftp = ftp_connection(); + $ftp->get($_) + or warn "$PROG: unable to download $_: $msg\n"; } }; }