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 -

/etc/secret-pw.txt

      

On a remote machine, I have a file -

/etc/secret-pw.txt

      

So,

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.

+3


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

.

+1


source


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

.

0


source







All Articles