Package: sftpretty
sftprettyA 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 decoratorHash function for integrity checkingImproved local & remote directory mappingImproved logging mechanismMore testsMulti-threaded directory transfersOpenSSH config file supportProgress notificationsSupport for ciphers, compression, digests, kex & key type optionsSupport for disabled algorithmsSupport for ED25519 & ECDSA keysSupport for private key passwordsThread-safe connection managerTransfer ResumptionExamplefromsftprettyimportCnOpts,Connection# BasicwithConnection('hostname',username='me',password='secret')assftp:# Temporarily chdir to public/.withsftp.cd('public'):# Upload file to public/ on remote.sftp.put('/my/local/filename')# Download a remote file from public/.sftp.get('remote_file')withConnection('hostname',private_key='~/.ssh/id_ed25519',private_key_pass='secret')assftp:# 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 authenticationwithConnection('hostname',username='me',password='secret')assftp:# 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 authenticationwithConnection('hostname',private_key='~/.ssh/id_ed25519')assftp:# 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 passwordwithConnection('hostname',private_key='~/.ssh/id_ed25519',private_key_pass='secret')assftp:# 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')withConnection('alias',cnopts=cnopts,private_key_pass='secret')assftp:# Rename existing file on remote serversftp.rename('/remote/old_name','/remote/new_name')# Pass custom host key file for verificationcnopts=CnOpts(knownhosts='sftpserver.pub')# Use connection options to set preferred encryption standardscnopts.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 filecnopts.log='/var/log/backups/daily.log'cnopts.log_level='debug'# Pass options object directly to connection objectwithConnection('hostname',cnopts=cnopts,private_key='~/.ssh/id_backup',private_key_pass='secret')assftp:# Aggressively retry important operationsftp.put_r('/local_backup','/remote_backup',backoff=2,delay=1,exceptions=socket.timeout,preserve_mtime=True,tries=11)Additional InformationProject:https://github.com/byteskeptical/sftprettyDownload:https://pypi.python.org/pypi/sftprettyDocumentation:https://docs.sftpretty.comLicense: BSDRequirementsparamiko >= 1.17.0SupportsTested on Python 3.6, 3.7, 3.8, 3.9, 3.10, 3.11Change Log1.1.4 (current, released 2024-1-04)missed the console logger in previous behavior change1.1.3 (released 2023-12-11)adding merge between ssh security options and paramiko compatibilitychanging default logger behavior from hooking into __main__1.1.2 (released 2023-10-24)added support for setting max_workers on ThreadPool functions1.1.1 (released 2023-08-28)added initial support for resuming existing transfers get() & put()added max_concurrent_prefetch_requests parameter to get() familyadded prefetch parameter to get() family1.1.0 (released 2023-08-15)added initial support for OpenSSH config-file support to CnOpts1.0.9 (released 2023-05-08)added drivedrop to bypass _adjust_cwd’s lack of Windows drive supportadded file_size logic and default remotepath fallback to putfomoved Connection.compress to CnOpts.compressregression in put_dagainremoved SKIP_IF_CI from all but one test in response to the aboveswitched to public key auth for all tests !¿macOS?¡switched from get_fingerprint() using md5 to helpers.hash using sha3_256test clean-up and major refactor1.0.7 (released 2023-02-27)fix regression in put_d1.0.6 (released 2023-01-15)allow CnOpts knownhost to be set to None directlystandardize on using is for None checks1.0.5 (released 2022-11-29)added log_level to connection optionsadded compression security option for Transportcode optimizations in _start_transport() and _set_authentication()moved compression on/off switch to Connection objectsprinkled debug messaging throughoutswitched to using native logging module instead of paramiko util1.0.4 (released 2022-09-24)added Windows Pure Path logic in put_d() and put_r() through localtree()fix for regression in _sftp_channel() causing UnboundLocalErrorimproved support for dot notation in known_hosts and private key fileremoved basicConfig() call for improved embedded behavior1.0.3 (released 2022-09-13)added disabled algorithms option for Transport1.0.2 (released 2022-09-09)added sort to localtree() for test continuitybug fix for typo in put_d()1.0.1 (released 2022-07-22)added key types security option for Transportbug fixes for close()default to private key authenticationenabled timeout setting for channel and transportimproved host key logginglocaltree & remotetree functions Windows compatiblestarted hosting on PyPiupdated tests and CI pipeline1.0.0 (released 2021-06-06)added ECDSA and ED25519 key support for authenticationadded digest and kex security options for Transportadded tests for additional functionalitydefault callback function for progress notificationshash function added to helpers for file verification optionimproved local and remote directory mappingimproved logging capabilitiesreplaced _sftp_connect with context aware channel managerretry decorator for automated recovery from failureswitched to using pathlib for all local filepath operationsupdated documentation and README with advanced examples