How to Not overwrite files with Net FTP

I’m writing a batch program to transfer files with Net::FTP and since I only want to transfer files that don’t already exist, I was looking for a setting or flag in Net:FTP to prevent overwriting. Google, perlmonks, and Claudio to the rescue

I added this little check to my perl script:

if ( $ftp->rename( $dest, $dest ) ) {
  print "File $dest already exists in $path \n";
} else {
  print "Put $local -> $dest \n";
  $ftp->put($local, $dest)
  or die "put failed ", $ftp->message;
}
$ftp->quit;

It is indeed ingenious – thank you Claudio, whoever you are 🙂

This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to How to Not overwrite files with Net FTP

Leave a Reply

Your email address will not be published. Required fields are marked *