Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Net::FTP - Check if file already exists locally before download

by mitabrev (Novice)
on Feb 12, 2019 at 10:22 UTC ( [id://1229784]=perlquestion: print w/replies, xml ) Need Help??

mitabrev has asked for the wisdom of the Perl Monks concerning the following question:

Hi Guys,

I've spent certain amount of hours searching for a solution and I couldn't find it.:(
Can you guys help me? I'm sure it's a easy do and that I can't see the forrest from all the trees.

I have a perl script with which I daily download files from a remote FTP server.
$ftp = Net::FTP->new($host, Debug => 0, Passive => 1); $ftp->login ($username, $password); $ftp->binary(); @set_of_files = $ftp->ls("*$thismonth-$thisday-$thisyear*.tar" +);
etc.
Is it possible with $ftp->get to check if a file already exists on a local folder before downloading it from ftp?

Thank you and best regards,


Mario

Replies are listed 'Best First'.
Re: Net::FTP - Check if file already exists locally before download
by hippo (Bishop) on Feb 12, 2019 at 10:52 UTC

    Is this what you are looking for?

    for my $file (@set_of_files) { $ftp->get ($file) unless -e $file; }
      Thanks! Exactly what I thought, couldn't see the easiest solution.

      Hi Monks,

      I got a follow up question. Is it possible to use the same command to check if file exists in two or more different directorites?

      for my $file (@set_of_files) { $ftp->get ($file) unless -e /dir1/$file; }

      so basically to check:

      unless -e /dir1/$file unless -e /dir2/$file

      something like that?

      Thanks again.

        for my $file (@set_of_files) { $ftp->get ($file) unless (-e "/dir1/$file" or -e "/dir2/$file"); }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1229784]
Approved by haukex
Front-paged by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-24 17:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found