Discussion:
scp no-clobber option??
Stewart Walters
2009-11-04 00:48:39 UTC
Permalink
I don't know.
But I, personally, prefer sftp.
It works like or better than ftp, is secure, plus you can check things
by executing host commands.
With no disrespect, it doesn't work like that at all. It provides the
user with a look-alike interface on the console, but what it does in
execution in the kernel as well as what it sends across the wire, are
radically different from standard ftp.

I've been searching for a noclobber option in scp or ssh (seeing as
openssh's scp just invokes ssh anyway), but I can't find one. The
closest I came was finding this page
(http://www.ma.hw.ac.uk/~katie/helpfulness.html) but unfortunately in
this instance "Katie's Page of Helpfulness" isn't that helpful :)

I haven't pulled the source code and searched for a noclobber option
though, which might be an option to you. It could be that the
functionality exists but is badly documented outside of source code.

rsync, with the right options, can be used to not to overwrite a
destination file. But for various reasons rsync might not be an option
for you (such as, in certain circumstances using rsync to upload to an
NFS mounted directory with root_squash enabled wont work).

The original poster at
http://www.unix.com/shell-programming-scripting/27312-scp-without-writting.html
asks the same question as you, but gets given a script to do it with rsh
(ugly). You could do that but the file (and I think the password to
authenticate) will be sent over an unencrypted channel.

There is a noclobber option in the bash shell that you *might* be able
to leverage on the remote system, but I'm not really sure in your
circumstances if that helps. The bash noclobber option is documented at
http://www.cyberciti.biz/tips/howto-keep-file-safe-from-overwriting.html

Apart from that, the only thing I can think of is that you write a
script to first ssh to the remote system using the -c option to launch a
command, and check that the destination file exists in the first place.
If it doesn't, only then use a second command for scp to copy it to the
remote system.

Still pretty ugly, but it might get the job done.

Anyway, I hope that helps.

Regards,

Stewart
Euan Thoms
2009-11-12 09:27:55 UTC
Permalink
Looks like rsync is my best option in future. Thanks Stewart for the good detail. So far, I have only used grsync (graphical frontend to rsync), before moving to unison, so will have to learn it proper (from command line). I do know that rsync is an excellent tool, however scp is easy because it's just like using cp, shame it doesn't have a noclobber option.
--
This message posted from opensolaris.org
Jan Pechanec
2009-11-13 11:41:08 UTC
Permalink
I've been searching for a noclobber option in scp or ssh (seeing as openssh's
scp just invokes ssh anyway), but I can't find one. The closest I came was
finding this page (http://www.ma.hw.ac.uk/~katie/helpfulness.html) but
unfortunately in this instance "Katie's Page of Helpfulness" isn't that helpful
:)
hi Stewart, there is no no-clobber option in scp.
I haven't pulled the source code and searched for a noclobber option though,
which might be an option to you. It could be that the functionality exists but
is badly documented outside of source code.
not the case, scp just opens the file without checking if it
exists or not.
Apart from that, the only thing I can think of is that you write a script to
first ssh to the remote system using the -c option to launch a command, and
check that the destination file exists in the first place. If it doesn't, only
then use a second command for scp to copy it to the remote system.
you can do something like this, in one command:

cat file | ssh xxx "[ -f file ] && exit; cat >file"

J.
--
Jan Pechanec
Loading...