in reply to Re: Script to check for multiple files on FTP and print the one missing
in thread Script to check for multiple files on FTP and print the one missing

Yes, for simplicity, ignore the *. Suppose i am checking for 3 files: abc.txt, xyz.txt, efg.txt. If all are present on FTP then it prints "all files are there". If xyz.txt and abc.txt are the only files on the FTP it will print "efg.txt is missing". The actual number of files i need to check for is about 20 which is why i'm trying to write it cleaner.
  • Comment on Re^2: Script to check for multiple files on FTP and print the one missing

Replies are listed 'Best First'.
Re^3: Script to check for multiple files on FTP and print the one missing
by zork42 (Monk) on Jul 01, 2013 at 05:07 UTC
    Are you using Net::FTP?
    Because that its documentation says that $ftp->ls($dir) returns a directory listing.
    Assuming that to be the case, then something like this should work.
    use strict; use warnings; my @files_to_check = ( 'abc.txt', 'xyz.txt', 'efg.txt' ); # list +of files to check my @directory_listing = $ftp->ls($dir); my %files_on_FTP_server; foreach my $file (@directory_listing) { # extra processing here? $files_on_FTP_server{$file} = 1; } foreach my $file (@files_to_check) { if ( ! $files_on_FTP_server{$file} ) { print "File $file is missin +g\n"; } }
    However, as I do not know the format of @directory_listing, you might need some extra processing where indicated on line 12.
    If @directory_listing contains a line of info for each file, you'd need a regexp to extract the file from each line, and you'd change line 10 from
    foreach my $file (@directory_listing) to:
    foreach my $line (@directory_listing)


    UPDATE: s/Net::FTP/Net::FTP/ (ie linkified it)
    s/that/its documentation/