Skip to main content

Build Status License Language

Scrippy, my scrangourou friend

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.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for scrippy-remote 4.0.1
File Size Uploaded
scrippy_remote-4.0.1.tar.gz 29.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for scrippy-remote 4.0.1
File Interpreter ABI Platform
scrippy_remote-4.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 55.4 kB

Release files / scrippy_remote-4.0.1.tar.gz

Download URL scrippy_remote-4.0.1.tar.gz
Size 29.7 kB
Tags Source
SHA-256 checksum
How to use checksums
175030197d22d8f932d7c6253ef3e2d5fa3a7131ced4b70a49bd4693bdd49197
BLAKE2b-256 checksum
How to use checksums
129e41020632db24d791289988b5c7fc2240bee056beb58868493ab5fe5bd6a7
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.1-py3-none-any.whl

Download URL scrippy_remote-4.0.1-py3-none-any.whl
Size 25.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0ec73ed4e35c3670e2d2167da95576efe83da0e4d5ffcc6f2d3e65cba0941263
BLAKE2b-256 checksum
How to use checksums
9fd44e0c962aef387487a2408a1f833ee8fc4a86d24554d1e28bacee6232e316
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.17

Release history Release notifications | RSS feed

This release

4.0.1 This release

2 release files

4.0.0

2 release files

3.0.4

2 release files

3.0.3

2 release files

3.0.2

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.0.15

2 release files

2.0.13

2 release files

2.0.12

2 release files

2.0.10

2 release files

2.0.9

2 release files

2.0.8

2 release files

2.0.7

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page