use strict; use warnings; use File::Find; use Net::FTP; use Cwd; my $ftp = Net::FTP->new("ftp.ncbi.nih.gov", Timeout => 30) or die "Cannot connect to server: $@"; my $dir = "/genomes/Bacteria"; $ftp->cwd($dir) or die "Cannot cd to " , $dir; my @directories = $ftp->ls() or die "cannot list any DIRs"; my @files; find( sub { push @files, $File::Find::name if /\.fna$/ }, @directories ) or die "can't find shit"; for(my $i=0; $i<@files; $i++){ print "$i","x hooray" } $ftp->quit; #### use warnings; use strict; use Net::FTP; my $ftp = Net::FTP->new("ftp.ncbi.nih.gov", Timeout => 30) or die "Cannot connect to server: $@"; ## login is mandatory, even if no user and password is specified: $ftp->login("anonymous",'-anonymous@') or die "Cannot login ", $ftp->message; my $dir = '/genomes/Bacteria'; ## move to the subdirectory: $ftp->cwd($dir) or die "Cannot cd to " , $ftp->message(); #print "part 1\n"; my @dir_listing = $ftp->ls() or die $ftp->message; ## note: you need to save DIRs as arrays before you can search for specific ## files or anything my @files; for(my $j=0; $j<@dir_listing; $j++){ ##list all the files in subdirs: my @file_list = $ftp-> ls($dir_listing[$j]) or die $ftp->message; ##weed out all the files you want and put them in an array my @found_files = grep(/.fna/, @file_list); push (@files, @found_files); } ##Make a resultfile to print all the files to: my $results = "D:/Genomes/results/filelist.dat"; open (OUTFILE, '>', $results) or die "Cannot write $!n"; for(my $i=0; $i<@files; $i++){ print OUTFILE "@files[$i]"; } close (OUTFILE); $ftp->quit;