datalad_next.url_operations.SshUrlOperations

class datalad_next.url_operations.SshUrlOperations(*, cfg: ConfigManager | None = None)[source]

Bases: UrlOperations

Handler for operations on ssh:// URLs

For downloading files, only servers that support execution of the commands 'ls -dln', 'awk', and 'cat' are supported. This includes a wide range of operating systems, including devices that provide these commands via the 'busybox' software.

Note

Any instance of SshUrlOperations must be deleted before ending the program, otherwise python might not exit. The reason is, that SshUrlOperations retains and reuses SSH connections for subsequent command execution. Each connection has two threads associated with it. Those threads are only terminated when the connection is closed. The destructor of SshUrlOperations closes all connections and terminates all associated threads.

close_shell_for(url: str)[source]

Close the ShellCommandExecutor for the url and remove it

delete(url: str, *, credential: str | None = None, timeout: float | None = None) Dict[source]

Delete the target of a shh://-URL

The target can be a file or a directory. delete will attempt to delete write protected targets (by setting write permissions). If the target is a directory, the complete directory and all its content will be deleted. delete will not modify the permissions of the parent of the target. That means, it will not delete a target in a write protected directory, but it will empty target, if target is a directory.

See datalad_next.url_operations.UrlOperations.delete() for parameter documentation and exception behavior.

Raises:

UrlOperationsResourceUnknown -- For deletion targets found absent.

download(from_url: str, to_path: Path | None, *, credential: str | None = None, hash: list[str] | None = None, timeout: float | None = None) Dict[source]

Download a file by streaming it through an SSH connection.

On the server-side, the file size is determined and sent. Afterwards the file content is sent via cat to the SSH client.

See datalad_next.url_operations.UrlOperations.download() for parameter documentation and exception behavior.

format_cmd(cmd: str, url: str) str[source]
ssh_shell_for(url: str) ShellCommandExecutor[source]

Get a ShellCommandExecutor for the url (cached or newly created)

stat(url: str, *, credential: str | None = None, timeout: float | None = None) Dict[source]

Gather information on a URL target, without downloading it

See datalad_next.url_operations.UrlOperations.stat() for parameter documentation and exception behavior.

upload(from_path: Path | None, to_url: str, *, credential: str | None = None, hash: list[str] | None = None, timeout: float | None = None) Dict[source]

Upload a file by streaming it through an SSH connection.

It, more or less, runs ssh <host> 'cat > <path>' or ssh <host> 'head -c <file-size> > <path>' on the remote side.

See datalad_next.url_operations.UrlOperations.upload() for parameter documentation and exception behavior.