b.t.s.SFTPTransport(ConnectedTransport) : class documentation

Part of bzrlib.transport.sftp View In Hierarchy

Transport implementation for SFTP access.
Method disconnect Disconnect the transport.
Method has Does the target location exist?
Method get Get the file at the given relative path.
Method get_bytes Get a raw string of the bytes for a file at the given location.
Method recommended_page_size See Transport.recommended_page_size().
Method put_file Copy the file-like object into the location.
Method put_file_non_atomic Copy the file-like object into the target location.
Method put_bytes_non_atomic Copy the string into the target location.
Method iter_files_recursive Walk the relative paths of all files in this transport.
Method mkdir Create a directory at the given path.
Method open_write_stream See Transport.open_write_stream.
Method append_file Append the text in the file-like object into the final
Method rename Rename without special overwriting
Method move Move the item at rel_from to the location at rel_to
Method delete Delete the item at relpath
Method external_url See bzrlib.transport.Transport.external_url.
Method listable Return True if this store supports listing.
Method list_dir Return a list of all files at the given location.
Method rmdir See Transport.rmdir.
Method stat Return the stat information for a file.
Method readlink See Transport.readlink.
Method symlink See Transport.symlink.
Method lock_read Lock the given file for shared (read) access.
Method lock_write Lock the given file for exclusive (write) access.
Method _remote_path Return the path to be passed along the sftp protocol for relpath.
Method _create_connection Create a new connection with the provided credentials.
Method _get_sftp Ensures that a connection is established
Method _readv See Transport.readv()
Method _sftp_readv Use the readv() member of fp to do async readv.
Method _put Helper function so both put() and copy_abspaths can reuse the code
Method _put_non_atomic_helper Undocumented
Method _mkdir Undocumented
Method _translate_io_exception Translate a paramiko or IOError into a friendlier exception.
Method _rename_and_overwrite Do a fancy rename on the remote server.
Method _sftp_open_exclusive Open a remote path exclusively.
Method _can_roundtrip_unix_modebits Return true if this transport can store and retrieve unix modebits.

Inherited from ConnectedTransport:

Method __init__ Constructor.
Method clone Return a new transport with root at self.base + offset
Method relpath Return the local path portion from a given absolute path
Method abspath Return the full url to the given relative path.
Method _user Undocumented
Method _password Undocumented
Method _host Undocumented
Method _port Undocumented
Method _path Undocumented
Method _scheme Undocumented
Static Method _split_url Undocumented
Static Method _unsplit_url Build the full URL for the given already URL encoded path.
Method _get_shared_connection Get the object shared amongst cloned transports.
Method _set_connection Record a newly created connection with its associated credentials.
Method _get_connection Returns the transport specific connection object.
Method _get_credentials Returns the credentials used to establish the connection.
Method _update_credentials Update the credentials of the current connection.
Method _reuse_for Returns a transport sharing the same connection if possible.

Inherited from Transport (via ConnectedTransport):

Method create_prefix Create all the directories leading down to self.base.
Method ensure_base Ensure that the directory this transport references exists.
Method get_segment_parameters Return the segment parameters for the top segment of the URL.
Method local_abspath Return the absolute path on the local filesystem.
Method has_multi Return True/False for each entry in relpaths
Method has_any Return True if any of the paths exist.
Method get_smart_medium Return a smart client medium for this transport if possible.
Method readv Get parts of the file at the given relative path.
Method get_multi Get a list of file-like objects, one for each entry in relpaths.
Method put_bytes Atomically put the supplied bytes into the given location.
Method mkdir_multi Create a group of directories
Method append_bytes Append bytes to a file at relpath.
Method append_multi Append the text in each file-like or string object to
Method copy Copy the item at rel_from to the location at rel_to.
Method copy_multi Copy a bunch of entries.
Method copy_to Copy a set of entries from self into another Transport.
Method copy_tree Copy a subtree from one relpath to another.
Method copy_tree_to_transport Copy a subtree from one transport to another.
Method move_multi Move a bunch of entries.
Method move_multi_to Move a bunch of entries to a single location.
Method delete_multi Queue up a bunch of deletes to be done.
Method delete_tree Delete an entire tree. This may require a listable transport.
Method __repr__ Undocumented
Method stat_multi Stat multiple files and return the information.
Method hardlink Create a hardlink pointing to source named link_name.
Method is_readonly Return true if this connection cannot be written to.
Method _translate_error Translate an IOError or OSError into an appropriate bzr error.
Method _pump Most children will need to copy from one file-like
Method _get_total Try to figure out how many entries are in multi,
Method _report_activity Notify that this transport has activity.
Method _update_pb Update the progress bar based on the current count
Method _iterate_over Iterate over all entries in multi, passing them to func,
Method _seek_and_read An implementation of readv that uses fp.seek and fp.read.
Method _sort_expand_and_combine Helper for readv.
Static Method _coalesce_offsets Yield coalesced offsets.
Method _redirected_to Returns a transport suitable to re-issue a redirected request.
def _remote_path(self, relpath):
Return the path to be passed along the sftp protocol for relpath.
Parametersrelpathis a urlencoded string.
def _create_connection(self, credentials=None):
Create a new connection with the provided credentials.

The credentials are only the password as it may have been entered interactively by the user and may be different from the one provided in base url at transport creation time.

ParameterscredentialsThe credentials needed to establish the connection.
ReturnsThe created connection and its associated credentials.
def disconnect(self):
Disconnect the transport.

If and when required the transport willl reconnect automatically.

def _get_sftp(self):
Ensures that a connection is established
def has(self, relpath):
Does the target location exist?
def get(self, relpath):
Get the file at the given relative path.
ParametersrelpathThe relative path to the file
def get_bytes(self, relpath):
Get a raw string of the bytes for a file at the given location.
ParametersrelpathThe relative path to the file
def _readv(self, relpath, offsets):
See Transport.readv()
def recommended_page_size(self):
See Transport.recommended_page_size().

For SFTP we suggest a large page size to reduce the overhead introduced by latency.

def _sftp_readv(self, fp, offsets, relpath):
Use the readv() member of fp to do async readv.

Then read them using paramiko.readv(). paramiko.readv() does not support ranges > 64K, so it caps the request size, and just reads until it gets all the stuff it wants.

def put_file(self, relpath, f, mode=None):
Copy the file-like object into the location.
ParametersrelpathLocation to put the contents, relative to base.
fFile-like object.
modeThe final mode for the file
def _put(self, abspath, f, mode=None):
Helper function so both put() and copy_abspaths can reuse the code
def _put_non_atomic_helper(self, relpath, writer, mode=None, create_parent_dir=False, dir_mode=None):
Undocumented
def put_file_non_atomic(self, relpath, f, mode=None, create_parent_dir=False, dir_mode=None):
Copy the file-like object into the target location.

This function is not strictly safe to use. It is only meant to be used when you already know that the target does not exist. It is not safe, because it will open and truncate the remote file. So there may be a time when the file has invalid contents.

ParametersrelpathThe remote location to put the contents.
fFile-like object.
modePossible access permissions for new file. None means do not set remote permissions.
create_parent_dirIf we cannot create the target file because the parent directory does not exist, go ahead and create it, and then try again.
def put_bytes_non_atomic(self, relpath, bytes, mode=None, create_parent_dir=False, dir_mode=None):
Copy the string into the target location.

This function is not strictly safe to use. See Transport.put_bytes_non_atomic for more information.

ParametersrelpathThe remote location to put the contents.
bytesA string object containing the raw bytes to write into the target file.
modePossible access permissions for new file. None means do not set remote permissions.
create_parent_dirIf we cannot create the target file because the parent directory does not exist, go ahead and create it, and then try again.
dir_modePossible access permissions for new directories.
def iter_files_recursive(self):
Walk the relative paths of all files in this transport.
def _mkdir(self, abspath, mode=None):
Undocumented
def mkdir(self, relpath, mode=None):
Create a directory at the given path.
def open_write_stream(self, relpath, mode=None):
See Transport.open_write_stream.
def _translate_io_exception(self, e, path, more_info='', failure_exc=PathError):
Translate a paramiko or IOError into a friendlier exception.
ParameterseThe original exception
pathThe path in question when the error is raised
more_infoExtra information that can be included, such as what was going on
failure_excParamiko has the super fun ability to raise completely opaque errors that just set "e.args = ('Failure',)" with no more information. If this parameter is set, it defines the exception to raise in these cases.
def append_file(self, relpath, f, mode=None):
Append the text in the file-like object into the final location.
def rename(self, rel_from, rel_to):
Rename without special overwriting
def _rename_and_overwrite(self, abs_from, abs_to):
Do a fancy rename on the remote server.

Using the implementation provided by osutils.

def move(self, rel_from, rel_to):
Move the item at rel_from to the location at rel_to
def delete(self, relpath):
Delete the item at relpath
def external_url(self):
See bzrlib.transport.Transport.external_url.
def listable(self):
Return True if this store supports listing.
def list_dir(self, relpath):
Return a list of all files at the given location.
def rmdir(self, relpath):
See Transport.rmdir.
def stat(self, relpath):
Return the stat information for a file.
def readlink(self, relpath):
See Transport.readlink.
def symlink(self, source, link_name):
See Transport.symlink.
def lock_read(self, relpath):
Lock the given file for shared (read) access. :return: A lock object, which has an unlock() member function
def lock_write(self, relpath):
Lock the given file for exclusive (write) access. WARNING: many transports do not support this, so trying avoid using it
ReturnsA lock object, which has an unlock() member function
def _sftp_open_exclusive(self, abspath, mode=None):
Open a remote path exclusively.

SFTP supports O_EXCL (SFTP_FLAG_EXCL), which fails if the file already exists. However it does not expose this at the higher level of SFTPClient.open(), so we have to sneak away with it.

WARNING: This breaks the SFTPClient abstraction, so it could easily break against an updated version of paramiko.

ParametersabspathThe remote absolute path where the file should be opened
modeThe mode permissions bits for the new file
def _can_roundtrip_unix_modebits(self):
Return true if this transport can store and retrieve unix modebits.

(For example, 0700 to make a directory owner-private.)

Note: most callers will not want to switch on this, but should rather just try and set permissions and let them be either stored or not. This is intended mainly for the use of the test suite.

Warning: this is not guaranteed to be accurate as sometimes we can't be sure: for example with vfat mounted on unix, or a windows sftp server.

API Documentation for Bazaar, generated by pydoctor at 2019-11-13 00:26:04.