1

scp with password less authentication is working fine but if delete a file on the source it will not get replicated ie the destination directory is not completely replaced with source. I can see the new files or modifications are properly get replicated.

scp -r /user/local/img root@192.168.18.73:/user/local/img
Aha
  • 409
  • 3
  • 8
  • 18

3 Answers3

5

scp is only a copy tool, so if you have to use scp, your only real choice is to empty the destination directory tree first.

Alternatively, you should probably look into using rsync, this will run over ssh using the passwordless setup you have now, and has many advantages (it can replicate deletes, only transfers changed data so copies are quicker, and can compress data during transfer). If you change your command to this one, you should get the results that you want (although test it first to make 100% sure it does what you're looking for!):

rsync -avz --del /user/local/img root@192.168.18.73:/user/local/img

gac
  • 459
  • 2
  • 8
1

scp works much like standard cp - it copies what you tell it to copy. Your command above says that it should copy the local folder /usr/local/img to /usr/local/img on the remote server; if the remote folder already exists, then it'll copy to /usr/local/img/img.

Xiong Chiamiov
  • 2,954
  • 2
  • 27
  • 30
1

scp is much the same as cp it doesn't delete destination files if the source has been deleted . If you want to keep source and destination directories in sync then rsync is the way forward.

rsync -avz --delete /user/local/img root@192.168.18.73:/user/local/img

you can also use rsync over ssh

rsync -avz -e ssh --delete /user/local/img root@192.168.18.73:/user/local/img
user9517
  • 115,471
  • 20
  • 215
  • 297