SCP transfer only modified files

39,595

Solution 1

rsync is your friend.

rsync -ru /source/directory/* [email protected]:/destination/directory

If you want it to delete files at the destination that no longer exist at the source, add the --delete option.

Solution 2

Generally one asks for scp because there is a reason. I.e. can't install rsyncd on the target.

files=`find . -newermt "-3600 secs"`

for file in $files
do
       sshpass -p "" scp "$file" "root@$IP://usr/local/www/current/$file"
done
Share:
39,595

Related videos on Youtube

Passionate Engineer
Author by

Passionate Engineer

Updated on September 18, 2022

Comments

  • Passionate Engineer
    Passionate Engineer almost 2 years

    I'm using below command to transfer files cross server

    scp -rc blowfish /source/directory/* [email protected]:/destination/directory
    

    Is there a way to transfer only files modified files just like update command for cp?

  • Jackson
    Jackson about 8 years
    Although, if you are syncing to a web server and that server caches HTML, you might not want to use --delete, since visitors on a stale page might request an asset that no longer exists.
  • Chris Pillen
    Chris Pillen over 5 years
    @Jackson a clean process will not include variable data like caches or configs in the sources.
  • jacobq
    jacobq over 5 years
    In some cases I have deal with servers outside of my domain that don't have rsync but have scp. Is there a comparable solution, even if it needs a few lines of scripting?
  • Mladen B.
    Mladen B. over 4 years
    The answer is helpful, but the question was can this be achieved with scp itself.
  • Kamran Hosseini
    Kamran Hosseini over 4 years
    @MladenB. How it can be achieved by scp?
  • Kamran Hosseini
    Kamran Hosseini over 4 years
    Is rsync as safe as scp?