Tux

...making Linux just a little more fun!

SCP Sensing Remote file presense

Smile Maker [britto_can at yahoo.com]


Tue, 22 Jul 2008 04:28:11 -0700 (PDT)

Folks:

When you do scp to remote machine, linux assumes to overwrite the target file if exists. Is there any way to check whether the target file exists and then copy the actual file.

--- Britto


Top    Back


Thomas Adam [thomas.adam22 at gmail.com]


Tue, 22 Jul 2008 13:30:33 +0100

2008/7/22 Smile Maker <britto_can@yahoo.com>:

> Folks:
>
>    When you do scp to remote machine, linux assumes to overwrite the target
> file if exists.Is there any way to check whether the target file exists and
> then copy the actual file.

Not directly, no. The best solution I can come up with is to use rsync over SSH which will allow for things like --update and --backup.

-- Thomas Adam


Top    Back


Ben Okopnik [ben at linuxgazette.net]


Tue, 22 Jul 2008 20:19:30 -0400

On Tue, Jul 22, 2008 at 04:28:11AM -0700, Smile Maker wrote:

>    Folks:                                                                     
>                                                                               
>       When you do scp to remote machine, linux assumes to overwrite the       
>    target file if exists.Is there any way to check whether the target file    
>    exists and then copy the actual file.                                      

You could use 'ssh' as a pipe instead of 'scp' (which does not provide the functionality you're looking for, as far as I know.) Untested:

tar czf - file1 file2 file3 ... | ssh user@host '(cd /my/target/dir; tar xvkzf -)'

The '-k' option to 'tar' on the receiver side "k"eeps the old files instead of overwriting them.

-- 
* Ben Okopnik * Editor-in-Chief, Linux Gazette * http://LinuxGazette.NET *


Top    Back