I suggest changing the permissions on the directory.
A short recap of your post with irrelevant parts left out:
I want to WRITE a file ... to a directory which is not writable for anyone bar the users. I am assuming that you are not logged in as that specific user.
That is, the 755 rights are:
- User: read (r), write (w), cd into directory (x)
- group: read (r),cd into directory (x)
- other: read (r),cd into directory (x)
Ergo only the user which own the directory is allowed to write to it. You might want to replace a writable file in that directory but that is the same as writing to a public dairy (777, not locked) in a locked cabinet. It fails because the cabinet is locked.
(If you think: why should I write to the directory and not just the file: The directory will be updated with things like last accessed, size, ....)
Other things which I assumed:
- You are not using ACL.
- This is not some special folder (such as /dev, /proc, ....)