Download to temporary filename, then move to final name.
Fix incorrect creation of directory while downloading.