36

I'm using below command to transfer files cross server

scp -rc blowfish /source/directory/* username@domain.net:/destination/directory

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

mob
  • 5
  • 1
Passionate Engineer
  • 553
  • 1
  • 7
  • 12

2 Answers2

63

rsync is your friend.

rsync -ru /source/directory/* username@domain.net:/destination/directory

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

Cristian Ciupitu
  • 6,396
  • 2
  • 42
  • 56
Flup
  • 7,978
  • 2
  • 32
  • 43
10

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
Dave M
  • 4,514
  • 22
  • 31
  • 30
  • Note that "-cmin N" is maybe a tad simpler. While N is a number of minutes the argument can be also a fractional number, e.g. "-cmin -0.5" gives you the files created in the last 30 seconds. In my experiments the argument had to be negative, tough. – Andreas Spindler Feb 16 '23 at 09:07