I should have pointed out the causes of the two problems the script resolves: ssh tramp at least sometimes preserves gid, and the gid on my org machine is an allowed gid on the webdav server, so files can end up with my normal gid instead of www. when mobileorg.org is rewritten by org (after pull), it ends up 644 gdt.www, but then MobileOrg can't write it.