Skip to main content

Pretty secure file transfer made easy.

Project description

A pretty quick and simple interface to paramiko SFTP. Provides multi-threaded routines with progress notifications for reliable, asynchronous transfers. A Python3 optimized fork of pysftp with additional features & improvements.

  • Built-in retry decorator

  • Channel cache

  • Hash function for integrity checking

  • Improved local & remote directory mapping

  • Improved logging mechanism

  • More tests

  • Multi-threaded directory transfers

  • OpenSSH config file support

  • Progress notifications

  • Support for ciphers, compression, digests, kex & key type options

  • Support for disabled algorithms

  • Support for ED25519 & ECDSA keys

  • Support for private key passwords

  • Thread-safe connection manager

  • Transfer Resumption

Example

from sftpretty import CnOpts, Connection


# Basic

with Connection('hostname', username='me', password='secret') as sftp:
    # Temporarily chdir to public/.
    with sftp.cd('public'):
        # Upload file to public/ on remote.
        sftp.put('/my/local/filename')
        # Download a remote file from public/.
        sftp.get('remote_file')


with Connection('hostname', private_key='~/.ssh/id_ed25519',
                private_key_pass='secret') as sftp:
    # Upload local directory to remote_directory.
    sftp.put_d('/my/local', '/remote_directory')

    # Recursively download a remote_directory and save it to /tmp locally.
    sftp.get_r('remote_directory', '/tmp')


# Advanced

# Use password authentication
with Connection('hostname', username='me', password='secret') as sftp:
    # Upload local directory to remote_directory. On occurance of any
    # exception or child of, passed in the tuple, retry the operation.
    # Between each attempt increment a pause equal to backoff * delay.
    # Run a total of tries (six) times including the first attempt.
    sftp.put_d('/my/local', '/remote_directory', backoff=2, delay=1,
               exceptions=(NoValidConnectionsError, socket.timeout,
                           SSHException), tries=6)


# Use public key authentication
with Connection('hostname', private_key='~/.ssh/id_ed25519') as sftp:
    # Resume the download of a bigfile and save it to /mnt locally.
    sftp.get('bigfile', '/mnt', preserve_mtime=True, resume=True)


# Use public key authentication with optional private key password
with Connection('hostname', private_key='~/.ssh/id_ed25519',
                private_key_pass='secret') as sftp:
    # Recursively download a remote_directory and save it to /tmp locally.
    # Don't confirm files, useful in a scenario where the server removes
    # the remote file immediately after download. Preserve remote mtime on
    # local copy. Limit the thread pool connections to the server.
    sftp.get_r('remote_directory', '/tmp', confirm=False,
               preserve_mtime=True, workers=6)


# Use OpenSSH config for public key authentication. Configuration
# connection values are prioritized when available. Credentials still need
# to be provided. There may be a significant delta between your ssh program
# and support for newer security option algorithms due to lagging support
# in paramiko.
cnopts = CnOpts(config='~/.ssh/config', knownhosts='server.pub')
with Connection('alias', cnopts=cnopts, private_key_pass='secret') as sftp:
    # Rename existing file on remote server
    sftp.rename('/remote/old_name', '/remote/new_name')


# Pass custom host key file for verification
cnopts = CnOpts(knownhosts='sftpserver.pub')
# Use connection options to set preferred encryption standards
cnopts.ciphers= ('aes256-ctr', 'aes128-ctr')
cnopts.digests = ('hmac-sha2-512', 'hmac-sha2-256')
cnopts.kex = ('ecdh-sha2-nistp521', 'ecdh-sha2-nistp384')
cnopts.key_types = ('ssh-ed25519', 'ecdsa-sha2-nistp521')
# Turn on verbose logging and set custom log file
cnopts.log = '/var/log/backups/daily.log'
cnopts.log_level = 'debug'
# Pass options object directly to connection object
with Connection('hostname', cnopts=cnopts, private_key='~/.ssh/id_backup',
                private_key_pass='secret') as sftp:
    # Aggressively retry important operation
    sftp.put_r('/local_backup', '/remote_backup', backoff=2, delay=1,
               exceptions=socket.timeout, preserve_mtime=True, tries=11)

API Diff

pysftp

sftpretty

cwd

cd [1]

makedirs

mkdir_p

walktree

{local,remote}tree [2]

Additional Information

Requirements

paramiko >= 2.7.0

Supports

Tested on Python 3.7, 3.8, 3.9, 3.10, 3.11, 3.12, 3.13, 3.14

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

sftpretty-1.2.0.tar.gz (32.1 kB view details)

Uploaded Source

Built Distribution

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

sftpretty-1.2.0-py3-none-any.whl (21.5 kB view details)

Uploaded Python 3

File details

Details for the file sftpretty-1.2.0.tar.gz.

File metadata

  • Download URL: sftpretty-1.2.0.tar.gz
  • Upload date:
  • Size: 32.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sftpretty-1.2.0.tar.gz
Algorithm Hash digest
SHA256 7369b25394bc5260e060042fe13a8d9f5da48c0cee6f6335f915fcd80fa201cf
MD5 0dd91d17722fea24bd74219fea114a87
BLAKE2b-256 c90e189767cf49364a658947581732c55aa6c1107d0f52f6426092189cd657cd

See more details on using hashes here.

File details

Details for the file sftpretty-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: sftpretty-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 21.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sftpretty-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e2b88641a6922e27e95cd397857a430cfcda022020e2fb30479270dd3deaf64c
MD5 a49f3c589713ad9d1c80f4efab2e6121
BLAKE2b-256 ba2f459738e820bd95ed928c6b4712984d4be09d87f16c59305d2bd637925259

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