Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

scp: disable overwriting of target file?

708 views
Skip to first unread message

Charles T. Smith

unread,
Jul 14, 2007, 10:28:59 AM7/14/07
to
Does anyone else chafe at the fact that you can't make scp fail if the
target file exists?

That would seem like an easy option to do - is there a reason other
than convention that it doesn't exist?

I also don't allow mv or cp to overwrite the targets - the need to do so
is only a small percentage of copy or move operations - in those cases, I
simply use /bin/cp or /bin/mv.

(I suspect that frustrations caused by those two commands overwriting
targets contributes to a large extent the bad associations many users have
with unix)

But it's not very effective to make a similar script for scp.

CaveSnow

unread,
Jul 16, 2007, 4:32:52 AM7/16/07
to

Well, I'm not answering your question as I am not experienced enough
to do so, but instead of using /bin/mv and /bin/cp can't you just use
the "-f" option: mv -f cp-f. The man pages say that it means force
and as a result these commands don't prompt for overwrite. However, I
think that scp can't do this because it can't "list" the target
directory so it cannot know if the files already exist. That's my
guess...

s. keeling

unread,
Jul 17, 2007, 2:15:38 PM7/17/07
to
Charles T. Smith <cts.p...@yahoo.com>:

> Does anyone else chafe at the fact that you can't make scp fail if the
> target file exists?

If you want handholding, you're in the wrong place. *nix tends to
assume you know what you're doing, so like a good bird dog, does what
it's been told to do. There's plenty of ways to manage this,
including simply listing the remote dir prior to copying.

Alternatively, instead of clobbering an existing file, why not copy to
a date-stamped version of the file?

cp blah $(date '+%Y%M%d')_blah # or `date '+%Y%M%d'`


--
Any technology distinguishable from magic is insufficiently advanced.
(*) Linux Counter #80292
- - http://www.faqs.org/rfcs/rfc1855.html Please, don't Cc: me.

Charles T. Smith

unread,
Jul 19, 2007, 5:01:16 PM7/19/07
to

Of course it can list the target directory. It just needs to do an
access(2) first - if it chooses to carry the Protocol Information across
to the peer.


0 new messages