493
493
except (IOError, paramiko.SSHException), e:
494
494
self._translate_io_exception(e, relpath, ': unable to append')
496
def copy(self, rel_from, rel_to):
497
"""Copy the item at rel_from to the location at rel_to"""
498
path_from = self._remote_path(rel_from)
499
path_to = self._remote_path(rel_to)
500
self._copy_abspaths(path_from, path_to)
502
def _copy_abspaths(self, path_from, path_to, mode=None):
503
"""Copy files given an absolute path
505
:param path_from: Path on remote server to read
506
:param path_to: Path on remote server to write
509
TODO: Should the destination location be atomically created?
510
This has not been specified
511
TODO: This should use some sort of remote copy, rather than
512
pulling the data locally, and then writing it remotely
515
fin = self._sftp.file(path_from, 'rb')
517
self._put(path_to, fin, mode=mode)
520
except (IOError, paramiko.SSHException), e:
521
self._translate_io_exception(e, path_from, ': unable copy to: %r' % path_to)
523
def copy_to(self, relpaths, other, mode=None, pb=None):
524
"""Copy a set of entries from self into another Transport.
526
:param relpaths: A list/generator of entries to be copied.
528
if isinstance(other, SFTPTransport) and other._sftp is self._sftp:
529
# Both from & to are on the same remote filesystem
530
# We can use a remote copy, instead of pulling locally, and pushing
532
total = self._get_total(relpaths)
534
for path in relpaths:
535
path_from = self._remote_path(relpath)
536
path_to = other._remote_path(relpath)
537
self._update_pb(pb, 'copy-to', count, total)
538
self._copy_abspaths(path_from, path_to, mode=mode)
542
return super(SFTPTransport, self).copy_to(relpaths, other, mode=mode, pb=pb)
544
496
def _rename(self, abs_from, abs_to):
545
497
"""Do a fancy rename on the remote server.
582
534
except (IOError, paramiko.SSHException), e:
583
535
self._translate_io_exception(e, path, ': failed to list_dir')
537
def rmdir(self, relpath):
538
"""See Transport.rmdir."""
539
path = self._remote_path(relpath)
541
return self._sftp.rmdir(path)
542
except (IOError, paramiko.SSHException), e:
543
self._translate_io_exception(e, path, ': failed to rmdir')
585
545
def stat(self, relpath):
586
546
"""Return the stat information for a file."""
587
547
path = self._remote_path(relpath)