in reply to copy only modified remote files

You've provided no code or haven't showed anything that you've tried, but there are several ways to do this. I'll leave it up to you to show us the code for the actual file transfers and logging into the remote system, but here's one way to check for last modification time.

#!/usr/bin/perl use strict; use warnings; my $file = "this.file"; if (-f $file){ my $mtime = (stat($file))[9]; my $modified_ago = time() - $mtime; my $modified_ago_minutes = sprintf("%.2d", $modified_ago / 60); if ($modified_ago_minutes > 120){ print "$file\n"; } }

-stevieb

Replies are listed 'Best First'.
Re^2: copy only modified remote files
by perl_help26 (Beadle) on Jul 07, 2015 at 13:56 UTC
    Thank you for your reply. I am just trying to understand which is more reliable/fast: checksum or mtime. The idea is that I want to check if the remote file was modified, before i copy it locally (to save up time). Also, is it possible to do checksum of the remote file before copying it locally? Thanks
      mtime will be faster in most if not all cases, much faster if your files are large.

      First, yes you can check on the remote system and there are a few ways you can do that. One is SSH into the remote machine, run a perl one-liner (or remote script) on the remote box to report back the mtime (or checksum).

      Getting a checksum would likely be quicker, but consider that you'll have to store the checksums somewhere then look them back up every program run for comparison, so that's likely to even things out.

      EDIT: per Laurent_R, mtime will be faster in the long run. I was testing on a miniscule few-byte file.

      -stevieb