425
425
# raise the original with its traceback if we can.
428
def non_atomic_put(self, relpath, f, mode=None, create_parent_dir=False):
429
"""Copy the file-like object into the target location.
431
This function is not strictly safe to use. It is only meant to
432
be used when you already know that the target does not exist.
433
It is not safe, because it will open and truncate the remote
434
file. So there may be a time when the file has invalid contents.
436
:param relpath: The remote location to put the contents.
437
:param f: File-like object.
438
:param mode: Possible access permissions for new file.
439
None means do not set remote permissions.
440
:param create_parent_dir: If we cannot create the target file because
441
the parent directory does not exist, go ahead and
442
create it, and then try again.
428
def _non_atomic_put_helper(self, relpath, writer, mode=None,
429
create_parent_dir=False):
444
430
abspath = self._remote_path(relpath)
446
432
# TODO: jam 20060816 paramiko doesn't publicly expose a way to
455
441
fout = self._sftp.file(abspath, mode='wb')
456
442
fout.set_pipelined(True)
458
444
except (paramiko.SSHException, IOError), e:
459
self._translate_io_exception(e, abspath, ': unable to open')
445
self._translate_io_exception(e, abspath,
461
448
# This is designed to chmod() right before we close.
462
449
# Because we set_pipelined() earlier, theoretically we might
484
471
self._translate_io_exception(e, abspath, ': unable to open')
485
472
_open_and_write_file()
474
def non_atomic_put_file(self, relpath, f, mode=None,
475
create_parent_dir=False):
476
"""Copy the file-like object into the target location.
478
This function is not strictly safe to use. It is only meant to
479
be used when you already know that the target does not exist.
480
It is not safe, because it will open and truncate the remote
481
file. So there may be a time when the file has invalid contents.
483
:param relpath: The remote location to put the contents.
484
:param f: File-like object.
485
:param mode: Possible access permissions for new file.
486
None means do not set remote permissions.
487
:param create_parent_dir: If we cannot create the target file because
488
the parent directory does not exist, go ahead and
489
create it, and then try again.
493
self._non_atomic_put_helper(relpath, writer, mode=mode,
494
create_parent_dir=create_parent_dir)
496
def non_atomic_put_bytes(self, relpath, bytes, mode=None,
497
create_parent_dir=False):
500
self._non_atomic_put_helper(relpath, writer, mode=mode,
501
create_parent_dir=create_parent_dir)
487
503
def iter_files_recursive(self):
488
504
"""Walk the relative paths of all files in this transport."""
489
505
queue = list(self.list_dir('.'))