Scp + Avoid copying if the same filename is on the remote computer?

Is it possible to specify the scp command - do not copy the file from the current computer to the case file on the remote computer.

for example

On my machine, I have a file -



On a remote machine, I have a file -




scp /etc/secret-pw.txt $remote_machine:/etc


Will destroy secret-pw.txt and scp won't ask questions about: overwrite target file

Is there an option to avoid copying if the file exists on the target machine using scp?

Update: I can't install rsync or any other program.


source to share

2 answers

You should use rsync

instead scp

. This will give you what you need.

If you cannot install rsync

(as you mentioned in the comments), you need to run the script ahead of time to check if the file exists and run it with ssh




SCP does not offer any option, unfortunately.

But you can use standard tools like:

ssh $remote_machine -- cp --no-clobber /dev/stdin /etc/secret-pw.txt < /etc/secret-pw.txt


Note that you get all the functionality with this trick cp




All Articles