sftpretty
raw JSON → 1.2.1 verified Mon Apr 27 auth: no python
A pretty, simple SFTP wrapper around paramiko with a high-level API for secure file transfer. Current version is 1.2.1, requires Python >=3.6. Release cadence is occasional, with recent releases roughly every few months.
pip install sftpretty Common errors
error AttributeError: module 'sftpretty' has no attribute 'Connection' ↓
cause Old import style (from sftpretty import sftpretty; sftpretty.Connection) used with sftpretty >=1.0.0 where API changed.
fix
from sftpretty import Connection
error ImportError: cannot import name 'CnOpts' ↓
cause Attempting to import CnOpts from a wrong location or an older version lacking that class.
fix
Use
from sftpretty import CnOpts; ensure sftpretty version >=1.0.0. error SSHException: Server 'example.com' not found in known_hosts ↓
cause Host key verification fails because the server's host key is not in the known_hosts file.
fix
Either disable host key checking (cnopts.hostkeys = None) or load the known_hosts file with cnopts.hostkeys.load('path/to/known_hosts').
error TypeError: __init__() got an unexpected keyword argument 'port' ↓
cause Connection constructor does not accept a 'port' argument; port is specified via hostname like 'host:port' or via the 'port' keyword in older paramiko but sftpretty expects it in the host string.
fix
Use connection = Connection('example.com:22', username='user', password='pass') or separate port argument? Actually sftpretty does accept port as an integer argument in version 1.2.x. Check docs. If error persists, use host:port format.
Warnings
gotcha sftpretty uses paramiko under the hood, so it inherits paramiko's GPL license. Ensure your project is compatible. ↓
fix Review paramiko's license implications before incorporating into proprietary software.
gotcha When using connection as a context manager (with statement), the connection closes upon exit. Do not attempt to use sftp object after the block ends. ↓
fix Perform all file operations inside the with block.
deprecated The 'cnopts' parameter in Connection constructor expects a CnOpts object; passing a dict is deprecated in some versions. Use CnOpts() explicitly. ↓
fix from sftpretty import CnOpts; cnopts = CnOpts(); Connection(..., cnopts=cnopts)
gotcha Host key checking is enabled by default. If you don't have the server's host key, the connection will fail. Use cnopts.hostkeys = None to disable (insecure) or cnopts.hostkeys.load('known_hosts') to add keys. ↓
fix Load known hosts file with cnopts.hostkeys.load('path/to/known_hosts') or set cnopts.hostkeys = None for testing only.
breaking In version 1.0.0, the API changed from `sftpretty.Connection(...)` to `Connection(...)` (import changes). Older code using `from sftpretty import sftpretty` will break. ↓
fix Change imports to `from sftpretty import Connection` and use `Connection(...)` directly.
Imports
- CnOpts
from sftpretty import CnOpts - Connection
from sftpretty import Connection - SFTPError
from sftpretty import SFTPError
Quickstart
from sftpretty import Connection
cnopts = CnOpts()
cnopts.hostkeys = None # disable host key checking (for demo only)
with Connection('example.com', username='user', password='pass', cnopts=cnopts) as sftp:
sftp.listdir()
print('Connected')