transfer as a tmp file and rename at the end