I have the following problem.
I need to replace a file with another one. As far as the new is transfered over the network, owner and group bits are lost. 
So I have the following idea. To save current permissions and file owner bits and than after replacing the file restore them.
Could you please suggest how to do this in Python or maybe you could propose a better way to achieve this.
You can use rsync facility to copy the file to remote location with same permissions. A simple os.system(rsync -av SRC <DEST_IP>:~/location/) call can do this. Another methods include using a subprocess.
Python save file permissions & owner/group and restore later