SFTP

class keg_storage.backends.sftp.SFTPStorage(host, username, key_filename, known_hosts_fpath, port=22, allow_agent=False, look_for_keys=False, linked_endpoint=None, secret_key=None, name='sftp')[source]

Create a signed JWT authorizing the user to perform the specified operations

delete(path: str)[source]

Delete the remote file specified by path.

Verify a JWT and extract the path and allowed operations

download(path: str, file_obj: IO, *, progress_callback: Optional[Callable[[int], None]] = None)

Copies a remote file at path to a file-like object file_obj.

If desired, a progress callback can be supplied. The function should accept an int parameter, which will be the number of bytes downloaded so far.

get(path: str, dest: str) → None

Copies a remote file at path to the dest path given on the local filesystem.

Create a URL pointing to the given linked_endpoint containing a JWT authorizing the user user to perform the given operations.

This is currently only implemented for flask based apps but you may override this method in your own subclass to support other frameworks.

To use this method you must provide secret_key and linked_endpoint to the constructor.

list(path: str)[source]

Returns a list of ListEntry`s representing files available under the directory or prefix given in `path.

open(path: str, mode: Union[keg_storage.backends.base.FileMode, str])[source]

Returns a instance of RemoteFile for the given path that can be used for reading and/or writing depending on the mode given.

put(path: str, dest: str) → None

Copies a local file at path to a remote file at dest.

upload(file_obj: IO, path: str, *, progress_callback: Optional[Callable[[int], None]] = None)

Copies the contents of a file-like object file_obj to a remote file at path

If desired, a progress callback can be supplied. The function should accept an int parameter, which will be the number of bytes uploaded so far.

class keg_storage.backends.sftp.SFTPRemoteFile(mode, path, client)[source]
close()[source]

Cleanup and deallocate any held resources. This method may be called multiple times on a single instance. If the file was already closed, this method should do nothing.

read(size: int)[source]

Read and return up to size bytes from the remote file. If the end of the file is reached this should return an empty bytes string.

write(data: bytes)[source]

Write the data buffer to the remote file.