Prevent overwriting of files when using Scp

Desert Ice picture Desert Ice · Nov 16, 2012 · Viewed 36.7k times · Source

I was copying some files using scp and i don't want to overwrite the already present files.

If i was using cp command, i think this can be done using cp -n.

Is there a similar option for scp, i went through the documentation of SCP and there seems to be no such option.

Is rsync or sftp the way to go solve this problem?

Addition Info:

OS: Ubuntu 12.04

Answer

osulehria picture osulehria · Nov 16, 2012

rsync seems to be the solution to your problem. Here's an example I got from here:

rsync -avz foo:src/bar /data/tmp

The -a option will preserve permissions, directory structure, ownership, and symlinks. You can also specify any of those options individually as well.

-v and -z mean verbose and compress respectively. You don't really need them although -z is nice if you are copying large files.