I am uploading files to my shell account using scp. As I need different permissions on the server than on my computer, I'd like to have a way to easily change the permissions upon upload without needing to ssh to the account and change them manually.
migrated from stackoverflow.com Jun 2 '11 at 0:48
|
If you're copying from a windows machine, you can use WinSCP to copy, and it has an option to set the permissions on the copied files after the upload. If not, I think your only choice is to execute a chmod on the server after the upload, which you could do remotely with an ssh command:
|
|||||||
|
|
You could do it using tar, ssh, & umask like this: on host 1:
on host2:
You can drop the -v switches to tar which I've included here merely so that you can see the files being tarred up on host1 and sent through STDOUT (aka. -) and then getting un-tarred on host2. NOTE: Why this works? Tar's default behavior is to unpack files using a remote user's umask. In the above example I've included the command umask to explicitly set it to something different which demonstrates that the remote tar is changing the permissions on the remote side. |
||||
|
|
|
I wrote a small script for the task in Python. You can do python script.py -p o+r some files some/dir/on/the/server/
|
|||
|
|
I have made some experiments with scp. For new files uploaded to the target server, the files have the same permissions as on the source server. If existing files are overwritten on the target server, the permissions for those files don't change. I have do these experiments with CentOS 4.6. |
|||
|
|
|
Assuming you are uploading to a UNIX variant, I think that the permissions ought to follow your UMASK settings. I don't recall off the top of my head which dot-files get processed for SCP, but if you set your UMASK in one of those the files you create will have it's permissions set based on it. It probably depends on what shell you use on the remote system. Whatever you do, don't use the -p option as it does the exact opposite of what you want. |
|||||
|
|
My preffered working solution would be to use Replace:
With:
This prevents you from authenticating twice. There are also a lot of other options with rsync which would probably add value such as being able to preserve owner, group, etc. |
||||
|
|
|
I would suggest setting up sticky bit on the folder so that the files you upload under that folder gets that permission automatically.
"1" used above sets the sticky bit. so you only have to upload one and not have to run another command afterwards. |
|||
|
|