Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I was wanting to use scp to move some files and overwrite any existing instances of these files on the destination server. Some of them may be read only which, of course, courses the scp to fail with "permission denied". I couldn't seem to find a --force type switch for scp; is this possible?

I am aware of rsync but this is not currently available on the destination server.

share|improve this question
add comment

3 Answers 3

up vote 1 down vote accepted

You cannot modify/overwrite any file if you don't have write permission, and no possible scp option may change that.

In order to solve it you should connect to the server first (using ssh for instance) and modify the permission on your file. If you don't know how to do it, here's a simple command which does the trick:

chmod +w /path/to/your/file

A few notes:

  • There's probably a reason why these files are read-only. Before doing anything, make sure you know why and that changing this is not going to break anything or introduce security holes.

  • If necessary you could remove the write permission after executing your scp command (with this: chmod -w /path/to/file).

  • If there are too many files with read-only permission, you need to hunt them down. find (at least the GNU version available in most Linux distributions) has a -perm test which you can use (man find for more info).

  • Someone might suggest that you connect as root or use sudo. It'll work, but for the love of God don't. I cannot begin to tell you how wrong this would be.

share|improve this answer
2  
As long as you have write perms on the containing directory, you can remove / rename a read-only file -- e.g. gist.github.com/4704937 –  Reed Kraft-Murphy Feb 4 '13 at 3:53
add comment

If SFTP is available on the server (it usually is), you can use SSHFS. This lets you mount the remote files on the client. You need an SFTP daemon on the server and FUSE on the client.

mkdir /net/myserver
sshfs myserver:/ /net/server

You can then use any local command such as cp, chmod, rsync, etc., without having to worry whether the files are local or remote. With rsync, pass the --no-whole-file option to tell it to use its bandwidth-saving delta-transfer algorithm (which is otherwise turned off when rsync believes that both paths are local).

rsync -a --no-whole-file somedir /net/myserver/somewhere
share|improve this answer
add comment

Rsync needn't be on the destination server; you can use

# rsync -avz -e ssh /path/to/files/ blah@somehost.com:/tmp/ 

Info on this here:

http://troy.jdmz.net/rsync/index.html

As said earlier though, don't take read only files lightly; I'll assume you know exactly what you're doing. Another method though is to scp or rsync the files into a /tmp/blah directory on the destination server, and then move them once written.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.