Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scp + Avoid copy if the same file name located on remote machine?

Tags:

linux

bash

scp

Is there any option to tell scp command - not copy file from current machine in case file exists on remote machine

For example

On my machine I have the file -

/etc/secret-pw.txt

On Remote machine I have also the file -

/etc/secret-pw.txt

So

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

Will destroy the secret-pw.txt, and scp will not ask questions about: overwrite the target file

Is there any option to avoid copy if file exist on target machine by scp?

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

like image 863
maihabunash Avatar asked Sep 15 '25 00:09

maihabunash


1 Answers

You should be using rsync instead of scp. It will give you what you need.

If you can't install rsync (as you mentioned in the comments) you need to run a script beforehand to check if file exists and run it with ssh.

like image 172
Pablo Santa Cruz Avatar answered Sep 17 '25 17:09

Pablo Santa Cruz