639
639
# set the file mode at create time. If it does, use it.
640
640
# But for now, we just chmod later anyway.
643
642
def _open_and_write_file():
644
643
"""Try to open the target file, raise error on failure"""
646
fout = self._sftp.file(abspath, mode='wb')
647
fout.set_pipelined(True)
649
except (paramiko.SSHException, IOError), e:
650
self._translate_io_exception(e, abspath, ': unable to open')
647
fout = self._sftp.file(abspath, mode='wb')
648
fout.set_pipelined(True)
650
except (paramiko.SSHException, IOError), e:
651
self._translate_io_exception(e, abspath, ': unable to open')
652
# This is designed to chmod() right before we close.
653
# Because we set_pipelined() earlier, theoretically we might
654
# avoid the round trip for fout.close()
656
self._sftp.chmod(abspath, mode)
653
# This is designed to chmod() right before we close.
654
# Because we set_pipelined() earlier, theoretically we might
655
# avoid the round trip for fout.close()
657
self._sftp.chmod(abspath, mode)
659
662
if not create_parent_dir:
660
663
_open_and_write_file()