scrippy_remote
SSH/SFTP, FTP/FTPS and CIFS client for the Scrippy framework.
Prerequisites
- Python >= 3.11
- The following modules, automatically installed:
- paramiko
- pysmb
Installation
With pip
pip install scrippy-remote
From source
git clone https://codeberg.org/scrippy/scrippy-remote.git
cd scrippy-remote
make install
Usage
scrippy_remote provides one class per protocol:
| Class | Module | Protocol |
|---|---|---|
Ssh |
scrippy_remote.ssh |
Remote command execution and file transfer over SSH/SFTP |
Ftp |
scrippy_remote.ftp |
File transfer over FTP, FTPS (implicit TLS) or FTPES (explicit TLS) |
Cifs |
scrippy_remote.cifs |
File transfer within a CIFS/Samba shared folder (limited support) |
Each class is used as a context manager: the connection is opened when entering the with block and closed when leaving it.
The three classes share the same methods:
| Method | Description |
|---|---|
get_file(remote_file, local_dir) |
Retrieve a remote file |
put_file(local_file, remote_dir) |
Transfer a file to the remote host |
local_mirror(remote_dir, local_dir) |
Copy a remote directory tree to the local host |
remote_mirror(local_dir, remote_dir) |
Copy a local directory tree to the remote host |
list_remote_dir(remote_dir) |
List the files (or directories) of a remote directory |
create_remote_dir(remote_dir) |
Create a remote directory |
delete_remote_file(remote_file) |
Delete a remote file |
delete_remote_dir(remote_dir) |
Delete a remote directory |
list_local_dir(), create_local_dir(), delete_local_file(), delete_local_dir() |
Local operations |
In addition, Ssh provides exec() to execute commands, and Cifs provides open() to read or write a remote file.
Example: copy a file from a FTP server to a SSH server, the local host acting as a buffer:
from scrippy_remote.ftp import Ftp
from scrippy_remote.ssh import Ssh
with Ftp(host="ftp.flying.circus",
username="luiggi.vercotti",
password="dead_parrot") as ftp:
ftp.get_file(remote_file="sketches/parrot.txt",
local_dir="/tmp")
with Ssh(username="luiggi.vercotti",
host="srv.flying.circus",
key="/home/luiggi.vercotti/.ssh/id_rsa") as ssh:
ssh.put_file(local_file="/tmp/parrot.txt",
remote_dir="/home/luiggi.vercotti/sketches",
create_dirs=True)
ssh.exec(command="chmod 640 /home/luiggi.vercotti/sketches/parrot.txt")
Error handling
All errors raise a scrippy_remote.ScrippyRemoteError. Its message starts with the error category, e.g. [SshTransferError]. The categories are listed in each protocol documentation.
Most methods accept an exit_on_error argument (default: True). When set to False, errors are only logged as warnings and the method goes on (e.g. a mirror skips the faulty file). Connection and argument errors are always raised.
from scrippy_remote import ScrippyRemoteError, logger
from scrippy_remote.ssh import Ssh
try:
with Ssh(username="luiggi.vercotti",
host="srv.flying.circus",
key="/home/luiggi.vercotti/.ssh/id_rsa") as ssh:
ssh.delete_remote_dir(remote_dir="/home/luiggi.vercotti/dead", recursive=True)
except ScrippyRemoteError as err:
logger.critical(f"{err}")
Documentation
The docstrings in the source code remain the reference documentation. make doc generates the class and package diagrams (classes_scrippy-remote.svg, packages_scrippy-remote.svg).
Tests
The tests need the test servers (SSH, FTP and Samba) provided as containers in tests/container:
make -C tests/container build run
python3 -m pip install .[dev]
make tests
The tests reach the servers through the sshd, vsftpd and samba host names, which must be resolvable (e.g. run the tests from a container attached to the container_default network).
Metadata
Release files for scrippy-remote 4.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| scrippy_remote-4.0.0.tar.gz | 29.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| scrippy_remote-4.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 55.3 kB
Release files / scrippy_remote-4.0.0.tar.gz
| Download URL | scrippy_remote-4.0.0.tar.gz |
|---|---|
| Size | 29.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7a244e712702ff27dd77fb555e7a6c7801181df6a902a4dcbbfd2718b7d6fff2
|
|
BLAKE2b-256 checksum How to use checksums |
cb14d4f1754c9d677fbf0e0070e41422bc4fca193b121d92b4678105172fe147
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.17
|
Release files / scrippy_remote-4.0.0-py3-none-any.whl
| Download URL | scrippy_remote-4.0.0-py3-none-any.whl |
|---|---|
| Size | 25.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5275ff39beed3df21ca305f1862ad5be892532f0534ba24c6525e6c0186f1fb6
|
|
BLAKE2b-256 checksum How to use checksums |
a13626d976d02790c50c495d889c09db1f123f07dc3f04fd17a2deee67f8abb4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.17
|