Skip to main content

Transfer files to/from a minimal machine with SSH access.

Project description

simple_ssh_copy

Transfer files to and from small or old POSIX-like devices over SSH.

This package intentionally avoids SFTP/SCP subsystems. It only needs a working SSH login and a few basic POSIX shell commands, so it is useful for minimal Linux systems, embedded devices, rescue environments, and older SSH servers.

Features

  • Upload a local file to a remote host.
  • Download a remote file to the local machine.
  • Download a remote directory recursively.
  • Password, empty-password, SSH agent, ~/.ssh key, and explicit private-key authentication.
  • Legacy SSH compatibility enabled by default:
    • HostKeyAlgorithms=+ssh-rsa
    • RSA public-key signing with ssh-rsa
    • MACs=+hmac-sha1-96,hmac-sha1,hmac-md5

For implementation notes, transfer flow, block sizes, and compatibility details, see Technical Details.

Install

pip install simple_ssh_copy

For local development:

pip install -e .

Command Line

Upload a file:

python -m simple_ssh_copy ./test-file.txt root@192.168.1.10:/home/root/test-file.txt

Download a file:

python -m simple_ssh_copy root@192.168.1.10:/home/root/test-file.txt ./test-file.txt

Use a non-default port:

python -m simple_ssh_copy ./test-file.txt root@192.168.1.10:2222:/home/root/test-file.txt

Use an explicit private key:

python -m simple_ssh_copy -i ~/.ssh/id_rsa ./test-file.txt root@192.168.1.10:/home/root/test-file.txt

On Windows:

python -m simple_ssh_copy -i C:\Users\neko\.ssh\id_rsa .\test-file.txt root@169.254.115.127:/home/root/test-file.txt

Increase the SSH timeout:

python -m simple_ssh_copy --timeout 60 ./test-file.txt root@192.168.1.10:/home/root/test-file.txt

When prompted for a password, press Enter for empty-password or key-only login. In that case the client also tries SSH agent and keys discoverable in ~/.ssh.

Python API

import simple_ssh_copy

hostname = "192.168.1.10"
username = "root"
password = ""

simple_ssh_copy.upload(
    hostname=hostname,
    username=username,
    password=password,
    files=[("./test-file.txt", "/home/root/test-file.txt")],
    key_filename="~/.ssh/id_rsa",
)

simple_ssh_copy.download(
    hostname=hostname,
    username=username,
    password=password,
    files=[("/home/root/test-file.txt", "./test-file.txt")],
    key_filename="~/.ssh/id_rsa",
)

simple_ssh_copy.download_dir(
    hostname=hostname,
    username=username,
    password=password,
    remote_dir="/home/root/logs",
    local_dir="./logs",
    key_filename="~/.ssh/id_rsa",
)

Run a remote command with the low-level client:

from simple_ssh_copy import SimpleSSHClient

with SimpleSSHClient(
    hostname="192.168.1.10",
    username="root",
    password="",
    key_filename="~/.ssh/id_rsa",
) as ssh:
    code, stdout, stderr = ssh.exec_cmd("uname -a")

Legacy SSH Notes

Some old devices require options like:

ssh -o HostKeyAlgorithms=+ssh-rsa \
    -o MACs=+hmac-sha1-96,hmac-sha1,hmac-md5 \
    -i ~/.ssh/id_rsa root@192.168.1.10

simple_ssh_copy enables the Paramiko equivalents by default, so the matching file-transfer command is usually:

python -m simple_ssh_copy -i ~/.ssh/id_rsa ./file root@192.168.1.10:/tmp/file

If you need stricter modern SSH behavior, pass allow_ssh_rsa_host_key=False from the Python API.

Path Format

Remote paths use one of these formats:

user@host:/remote/path
user@host:port:/remote/path

Only local-to-remote and remote-to-local transfers are supported. Remote-to- remote transfers are not supported.

Limitations

  • The remote host must provide a POSIX-like shell.
  • Non-POSIX SSH servers, such as Windows command-shell SSH sessions, are not supported and fail with a clear error.
  • Upload uses mkdir and base64 on the remote host.
  • Upload sends base64 fragments through bounded remote commands, then decodes the assembled temporary file on the remote host.
  • Download uses stat, dd, and find for directory downloads.
  • Directory upload is not implemented.
  • Very large uploads may be slower than real SCP/SFTP because data is written through remote shell commands.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simple_ssh_copy-0.1.8.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simple_ssh_copy-0.1.8-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file simple_ssh_copy-0.1.8.tar.gz.

File metadata

  • Download URL: simple_ssh_copy-0.1.8.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.11.15 Windows/10

File hashes

Hashes for simple_ssh_copy-0.1.8.tar.gz
Algorithm Hash digest
SHA256 786c8c1485a70025971fa3c277eb418e891c0ab5114020498fab8ba1f7c6cd35
MD5 380204818b9c30fef0d8384d51bc11ea
BLAKE2b-256 8c6ca05fbe12b0563413d1a31c897bc0bc17bc05718c6cf8fa6320d3f987d2bd

See more details on using hashes here.

File details

Details for the file simple_ssh_copy-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: simple_ssh_copy-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.11.15 Windows/10

File hashes

Hashes for simple_ssh_copy-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 0989e0c86555e0bf979b08c7240b22b8c142b86af7b500e677dd9403108e2161
MD5 a932781bb43a6b82e158c250eea7c8de
BLAKE2b-256 aba5e1337a244dd30eea29459f0ab5de897c9fde257208fce8272fac8a918ccc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page