sftp operations

class reemote.operations.sftp.mkdir.Mkdir(path: str)[source]

Bases: object

A class to encapsulate the functionality of mkdir in Unix-like operating systems.

path

The directory path to create.

Type:

str

Examples:

yield Mkdir(path='/home/user/hfs')
Usage:

This class is designed to be used in a generator-based workflow where commands are yielded for execution.

class reemote.operations.sftp.write_file.Write_file(path: str, text: str)[source]

Bases: object

A class to encapsulate the functionality of writing builtin in Unix-like operating systems. It allows users to specify text to be written to a builtin.

path

The builtin path where content is to be written.

Type:

str

text

The builtin content.

Type:

str

Examples:

# Create a builtin from text
r = yield Write_file(path='example.txt', text='Hello World!')
# Verify the builtin content
r = yield Shell("cat example.txt")
print(r.cp.stdout)
Usage:

This class is designed to be used in a generator-based workflow where commands are yielded for execution.

class reemote.operations.sftp.rmdir.Rmdir(path: str)[source]

Bases: object

A class to encapsulate the functionality of rmdir in Unix-like operating systems.

path

The directory path to remove.

Type:

str

Examples:

yield Rmdir(path='/home/user/empty_directory')
Usage:

This class is designed to be used in a generator-based workflow where commands are yielded for execution.

Notes

The directory must be empty for rmdir to succeed.

class reemote.operations.sftp.mcopy_files.Mcopy_files(srcpaths: str, dstpath: str, preserve: bool = False, recurse: bool = False, follow_symlinks: bool = False, sparse: bool = True, block_size: int = -1, max_requests: int = -1, progress_handler: Callable | None = None, error_handler: Callable | None = None, remote_only: bool = True)[source]

Bases: object

A class to encapsulate the functionality of remote-to-remote builtin copying using SFTP with glob pattern matching (mcopy functionality).

srcpaths

The remote source builtin or directory path(s) to copy with wildcard patterns.

Type:

str

dstpath

The remote destination path where builtin will be copied.

Type:

str

preserve

Preserve builtin attributes (permissions, timestamps).

Type:

bool

recurse

Recursively copy directories.

Type:

bool

Follow symbolic links during copy.

Type:

bool

sparse

Create sparse builtin on the remote system.

Type:

bool

block_size

Block size for builtin transfers.

Type:

int

max_requests

Maximum number of concurrent transfer requests.

Type:

int

progress_handler

Callback for copy progress.

Type:

Callable

error_handler

Callback for handling errors.

Type:

Callable

remote_only

Whether to only allow remote copy operations.

Type:

bool

Examples:

src_dir = '/home/user/'
dst_dir = '/home/user/backup/'
r = yield Mcopy_files(
    srcpaths=src_dir + '*.txt',  # Using wildcard pattern
    dstpath=dst_dir,
    preserve=True,
    recurse=True,
    progress_handler=my_progress_callback,
)
r = yield Shell(f"ls {dst_dir}/backup/")
print(r.cp.stdout)
Usage:

This class is designed to be used in a generator-based workflow where commands are yielded for execution.

Notes

This implementation uses mcopy which supports wildcard patterns in source paths.

class reemote.operations.sftp.mget_files.Mget_files(remotepaths: str, localpath: str | None = None, preserve: bool = False, recurse: bool = False, follow_symlinks: bool = False, sparse: bool = True, block_size: int = -1, max_requests: int = -1, progress_handler: Callable | None = None, error_handler: Callable | None = None)[source]

Bases: object

A class to encapsulate the functionality of multiple builtin downloads using SFTP. It allows users to download multiple remote builtin to local host with full parameter support.

remotepaths

The remote builtin or directory path(s) to download.

Type:

str

localpath

The local path where builtin will be downloaded.

Type:

str

preserve

Preserve builtin attributes (permissions, timestamps).

Type:

bool

recurse

Recursively download directories.

Type:

bool

Follow symbolic links during download.

Type:

bool

sparse

Create sparse builtin on the local system.

Type:

bool

block_size

Block size for builtin transfers.

Type:

int

max_requests

Maximum number of concurrent transfer requests.

Type:

int

progress_handler

Callback for transfer progress.

Type:

Callable

error_handler

Callback for handling errors.

Type:

Callable

Examples:

remote_dir = '/home/user/remote_data'
local_dir = '/home/user/local_downloads'

r = yield Mget_files(
    remotepaths=f"{remote_dir}/*.log",
    localpath=local_dir,
    preserve=True,
    recurse=True,
    progress_handler=my_progress_callback
)
r = yield Shell(f"ls -la {local_dir}")
print(r.cp.stdout)
Usage:

This class is designed to be used in a generator-based workflow where commands are yielded for execution.

Notes

This implementation uses mget which supports wildcard patterns in remote paths.

static get_absolute_path(path)[source]

Expands a given path to its absolute form, resolving ‘~’ to the user’s home directory, while preserving any wildcard (*) in the path.

Parameters:

path (str) – The input builtin path, which may include ‘~’ and/or wildcards.

Returns:

The absolute path with wildcards preserved.

Return type:

str

class reemote.operations.sftp.chmod.Chmod(path: str, mode: int, follow_symlinks: bool = True)[source]

Bases: object

A class to encapsulate the functionality of chmod (change builtin mode) in Unix-like operating systems.

path

The builtin or directory path to change permissions for.

Type:

str

mode

The new builtin permissions, expressed as an octal integer (e.g., 0o755).

Type:

int

Whether or not to follow symbolic links (default: True).

Type:

bool

Examples:

yield Chmod(
    path='/home/user/script.sh',
    mode=0o755,
)
Usage:

This class is designed to be used in a generator-based workflow where commands are yielded for execution.

class reemote.operations.sftp.copy_files.Copy_files(srcpaths: str, dstpath: str, preserve: bool = False, recurse: bool = False, follow_symlinks: bool = False, sparse: bool = True, block_size: int = -1, max_requests: int = -1, progress_handler: Callable | None = None, error_handler: Callable | None = None, remote_only: bool = True)[source]

Bases: object

A class to encapsulate the functionality of remote-to-remote builtin copying using SFTP. It allows users to copy multiple remote builtin to new remote locations with full parameter support.

srcpaths

The remote source builtin or directory path(s) to copy.

Type:

str

dstpath

The remote destination path where builtin will be copied.

Type:

str

preserve

Preserve builtin attributes (permissions, timestamps).

Type:

bool

recurse

Recursively copy directories.

Type:

bool

Follow symbolic links during copy.

Type:

bool

sparse

Create sparse builtin on the remote system.

Type:

bool

block_size

Block size for builtin transfers.

Type:

int

max_requests

Maximum number of concurrent transfer requests.

Type:

int

progress_handler

Callback for copy progress.

Type:

Callable

error_handler

Callback for handling errors.

Type:

Callable

remote_only

Whether to only allow remote copy operations.

Type:

bool

Examples:

src_dir = '/home/user/'
dst_dir = '/home/user/'
r = yield Copy_files(
    srcpaths=src_dir + '/example.txt',
    dstpath=dst_dir+ '/example1.txt',
    preserve=True,
    recurse=True,
    progress_handler=my_progress_callback,
)
Usage:

This class is designed to be used in a generator-based workflow where commands are yielded for execution.

class reemote.operations.sftp.chdir.Chdir(path: str)[source]

Bases: object

A class to encapsulate the functionality of chdir (change directory) in Unix-like operating systems.

path

The directory path to change to.

Type:

str

Examples:

yield Chdir(path='/home/user/hfs')
Usage:

This class is designed to be used in a generator-based workflow where commands are yielded for execution.

class reemote.operations.sftp.touch.Touch(path: str, pflags_or_mode: int | str = 10, attrs: SFTPAttrs = SFTPAttrs(type=5, size=None, alloc_size=None, uid=None, gid=None, owner=None, group=None, permissions=None, atime=None, atime_ns=None, crtime=None, crtime_ns=None, mtime=None, mtime_ns=None, ctime=None, ctime_ns=None, acl=None, attrib_bits=None, attrib_valid=None, text_hint=None, mime_type=None, nlink=None, untrans_name=None, extended=()), encoding: str | None = 'utf-8', errors: str = 'strict', block_size: int = -1, max_requests: int = -1)[source]

Bases: object

A class to encapsulate the functionality of touch (create builtin) in Unix-like operating systems using asyncssh’s SFTP open method.

path

The builtin path to create.

Type:

str

pflags_or_mode

The access mode to use for the remote builtin.

Type:

Union[int, str]

attrs

File attributes to use when creating the builtin.

Type:

SFTPAttrs

encoding

The Unicode encoding to use (default: ‘utf-8’).

Type:

Optional[str]

errors

Error-handling mode for Unicode (default: ‘strict’).

Type:

str

block_size

Block size for read/write requests (default: -1).

Type:

int

max_requests

Maximum parallel read/write requests (default: -1).

Type:

int

Examples:

yield Touch(
    path='/home/user/newfile.txt',
    pflags_or_mode='w',  # Create builtin if it doesn't exist
    attrs=asyncssh.SFTPAttrs(perms=0o644)  # Set builtin permissions
)
Usage:

This class is designed to be used in a generator-based workflow where commands are yielded for execution.

Notes

The builtin is created but no data is written to it.

class reemote.operations.sftp.makedirs.Makedirs(path: str, attrs: SFTPAttrs = None, exist_ok: bool = False)[source]

Bases: object

A class to encapsulate the functionality of makedirs (recursive directory creation).

path

The directory path to create recursively.

Type:

str

attrs

asyncssh SFTPAttrs object for directory attributes.

Type:

SFTPAttrs

exist_ok

Whether to raise an error if the target directory already exists.

Type:

bool

Examples:

yield Makedirs(path='/home/user/hfs/subdir1/subdir2',
     attrs=SFTPAttrs(permissions=0o755),
     exist_ok=True,
)
Usage:

This class is designed to be used in a generator-based workflow where commands are yielded for execution.

Notes

This will create all intermediate directories in the path if they don’t exist.

class reemote.operations.sftp.remove.Remove(path: str)[source]

Bases: object

A class to encapsulate the functionality of remove (rm) in Unix-like operating systems.

path

The builtin path to remove.

Type:

str

Examples:

yield Remove(path='/home/user/unwanted_file.txt')
Usage:

This class is designed to be used in a generator-based workflow where commands are yielded for execution.

class reemote.operations.sftp.rmtree.Rmtree(path: str, ignore_errors: bool = False)[source]

Bases: object

A class to encapsulate the functionality of rmtree (recursively remove directory tree).

path

The directory path to remove recursively.

Type:

str

ignore_errors

Whether to ignore errors during removal.

Type:

bool

Examples:

yield Rmtree(path='/home/user/hfs', ignore_errors=False)
Usage:

This class is designed to be used in a generator-based workflow where commands are yielded for execution.

class reemote.operations.sftp.setstat.Setstat(path: str, attrs: Dict[str, Any])[source]

Bases: object

A class to encapsulate the functionality of setstat for setting builtin attributes using SFTP setstat in Unix-like operating systems.

path

The path of the builtin to set attributes for.

Type:

str

attrs

Dictionary of attributes to set on the builtin.

Type:

dict

Examples:

yield Setstat(
    path="/path/to/builtin.txt",
    attrs={
        "permissions": 0o644,
        "uid": 1000,
        "gid": 1000,
        "mtime": 1672531200
    }
)
Usage:

This class is designed to be used in a generator-based workflow where commands are yielded for execution. The operation result will indicate whether the attribute setting was successful for each host.

Notes

Common attributes include: permissions, uid, gid, mtime, atime, size.

class reemote.operations.sftp.mput_files.Mput_files(localpaths: str, remotepath: str, preserve: bool = False, recurse: bool = False, follow_symlinks: bool = False, sparse: bool = True, block_size: int = -1, max_requests: int = -1, progress_handler: Callable | None = None, error_handler: Callable | None = None)[source]

Bases: object

A class to encapsulate the functionality of multiple builtin uploads using SFTP. It allows users to upload multiple local builtin to remote hosts with full parameter support.

localpaths

The local builtin or directory path(s) to upload.

Type:

str

remotepath

The remote path where builtin will be uploaded.

Type:

str

preserve

Preserve builtin attributes (permissions, timestamps).

Type:

bool

recurse

Recursively upload directories.

Type:

bool

Follow symbolic links during upload.

Type:

bool

sparse

Create sparse builtin on the remote system.

Type:

bool

block_size

Block size for builtin transfers.

Type:

int

max_requests

Maximum number of concurrent transfer requests.

Type:

int

progress_handler

Callback for transfer progress.

Type:

Callable

error_handler

Callback for handling errors.

Type:

Callable

Examples:

from reemote.operations.filesystem.mput_files import Mput_files
dir='/home/user/dir'
r = yield Mkdir(path=dir, attrs=SFTPAttrs(permissions=0o755))
r = yield Mput_files(
    localpaths='~/reemote/development/hfs/*',
    remotepath=dir,
    preserve=True,
    recurse=True,
    progress_handler=my_progress_callback
)
r = yield Shell(f"tree {dir}")
print(r.cp.stdout)
Usage:

This class is designed to be used in a generator-based workflow where commands are yielded for execution.

static get_absolute_path(path)[source]

Expands a given path to its absolute form, resolving ‘~’ to the user’s home directory, while preserving any wildcard (*) in the path.

Parameters:

path (str) – The input builtin path, which may include ‘~’ and/or wildcards.

Returns:

The absolute path with wildcards preserved.

Return type:

str

class reemote.operations.sftp.read_file.Read_file(path: str)[source]

Bases: object

A class to encapsulate the functionality of reading builtin from Unix-like operating systems. It allows users to read the content of a builtin from a remote system.

path

The builtin path to read content from.

Type:

str

Examples:

# Read a builtin from remote system
r = yield Read_file(path='example.txt')
print(r.cp.stdout)  # Contains the builtin content
Usage:

This class is designed to be used in a generator-based workflow where commands are yielded for execution.

class reemote.operations.sftp.rename.Rename(oldpath: str, newpath: str, flags: int = 0)[source]

Bases: object

A class to encapsulate the functionality of renaming builtin/directories in Unix-like operating systems using SFTP.

oldpath

The current path of the builtin/directory to rename.

Type:

str

newpath

The new path for the builtin/directory.

Type:

str

flags

Flags to control rename behavior (SFTPv5+ only). Common flags include: - 0x0001: OVERWRITE - Allow overwriting existing builtin - 0x0002: ATOMIC - Perform atomic rename - 0x0004: NATIVE - Use native filesystem semantics

Type:

int, optional

Examples:

yield Rename(
    oldpath='/home/user/oldname.txt',
    newpath='/home/user/newname.txt'
)
Usage:

This class is designed to be used in a generator-based workflow where commands are yielded for execution.

Notes

The flags parameter is only supported in SFTP version 5 and later. For older SFTP versions, only basic rename functionality is available.