pysftp-ng
A maintained, drop-in fork of pysftp. Your code still says
import pysftp and uses the same API, but it now works with current paramiko (3.4 through 5.x)
and Python 3.9 through 3.14.
Documentation: pysftp-ng.readthedocs.io
Why this exists
pysftp 0.2.9 came out in July 2016 and is still installed more than 11 million times a month.
It no longer works with current dependencies. paramiko 4.0 removed DSA keys, so a fresh
pip install pysftp now fails the moment you import it:
ImportError: cannot import name 'DSSKey' from 'paramiko'
There has been no upstream release since 2016. pysftp-ng fixes that break and a set of long-standing bugs, and keeps the API stable so existing code keeps running.
Switching over
pip uninstall -y pysftp
pip install pysftp-ng
No code changes are needed. In requirements.txt or pyproject.toml, replace pysftp with
pysftp-ng. Don't install both packages, because they provide the same pysftp module.
Troubleshooting pysftp errors
These are the errors pysftp 0.2.9 prints for the problems pysftp-ng fixes. Each links to a page with the cause and the fix.
ImportError: cannot import name 'DSSKey' from 'paramiko'AttributeError: 'Connection' object has no attribute '_sftp_live'SSHException: No hostkey for host ... found.Incompatible ssh peer (no acceptable host key)SSHException: unpack requires a buffer of 4 bytes(Ed25519 or ECDSA key in OpenSSH format)SSHException: encountered EC key, expected DSA key(ECDSA key in PEM format)
Usage
import pysftp
with pysftp.Connection("sftp.example.com", username="me", private_key="~/.ssh/id_ed25519") as sftp:
sftp.put("report.csv", "/upload/report.csv")
with sftp.cd("/download"):
sftp.get_r(".", "local-copy")
Extra connection options go on a CnOpts object:
cnopts = pysftp.CnOpts() # loads ~/.ssh/known_hosts
cnopts.timeout = 10 # new: limit for connecting, the handshake and logging in
with pysftp.Connection(
"sftp.example.com", port=2222, username="me", password="...", cnopts=cnopts
) as sftp:
print(sftp.listdir())
pysftp-ng 0.4.0 adds four more options, all off by default: keepalive, sock for servers behind
a jump host, allow_agent and ssh_config. The
connection options page covers each one.
What's fixed compared with pysftp 0.2.9
Each item below has a test in tests/. Tests marked regression reproduce bugs in pysftp 0.2.9.
- paramiko 4 and 5. Imports and runs without DSA. On paramiko < 4, DSA keys still work.
- Modern keys. Ed25519 and ECDSA key files work, encrypted or not, in OpenSSH or PEM format.
You can also pass any paramiko key object, such as
Ed25519KeyorAgentKey, asprivate_key. - Default keys. With no password or key given, pysftp-ng tries
~/.ssh/id_rsa,id_ecdsaandid_ed25519in OpenSSH's order and uses the first one the server accepts. 0.2.9 only looked forid_rsaandid_dsa. - known_hosts on non-standard ports. OpenSSH stores these as
[host]:port, including in hashed form. pysftp-ng finds them; 0.2.9 failed with "No hostkey for host ... found". - Hosts with several known keys. pysftp-ng only negotiates key types that are in known_hosts
and accepts any key that matches. 0.2.9 pinned whichever key was listed first. If the server had
retired that key type, or the first line was an old
ssh-dsskey, the connection failed with "Incompatible ssh peer". - Cleaner failures. No more
AttributeError: 'Connection' object has no attribute '_sftp_live'hiding the real error. A failed connection closes its transport. - Logging.
close()removes only the log handler it added. 0.2.9 removed every handler on theparamikologger, including your application's. - Windows paths.
put_randput_dbuild remote paths with/on every OS (0.2.9 sent backslashes from Windows), and they no longer change the process's working directory. get_r. Works on Windows clients, creates missing local directories, and no longer crashes on a broken symlink.readlink. A relative link target is resolved from the link's own directory. 0.2.9 used the current directory, so links in other directories gave wrong paths.- Speed.
walktreesends one listing request per directory instead of onestatper entry. - Path traversal. If a server returns a file name that would land outside the target
directory, such as
../../.bashrc,get_r,get_dandwalktreeskip it with a warning. - Smaller fixes. New
CnOpts.timeoutoption. The username falls back to the OS user whenLOGNAMEisn't set, as on Windows.ConnectionExceptionhas a readable message.
Compatibility
- The public API of pysftp 0.2.9 is kept: same names, arguments and return values. The deprecated
logandciphersarguments still work and emit aDeprecationWarning. - Behaviour changes are limited to the fixes above. The changelog lists every one.
- The test suite runs against Python 3.9–3.14 and paramiko 3.4, 3.5, 4.0 and 5.1. It uses an in-process SFTP server, so no external server is needed. In CI, a second suite runs the API against a real OpenSSH server in Docker.
Security
Host key checking is on by default and verifies the server before any password or key is sent.
Setting cnopts.hostkeys = None turns verification off and exposes you to man-in-the-middle
attacks, so don't do it outside a test environment.
To report a vulnerability, see SECURITY.md.
Credits
pysftp was written by Jeff Hinrichs (Dundee Media & Technology), with contributions from Don Reilly, James Kruth and Nick Robinson-Wall. pysftp-ng is forked from the 0.2.9 release and keeps its BSD 3-Clause license.
Contributing
Bug reports and pull requests are welcome. See CONTRIBUTING.md.
Metadata
Release files for pysftp-ng 0.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pysftp_ng-0.4.1.tar.gz | 44.3 kB | With provenance | Details for pysftp_ng-0.4.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pysftp_ng-0.4.1-py3-none-any.whl | Python 3 | none | any | Details for pysftp_ng-0.4.1-py3-none-any.whl |
Total release size: 67.1 kB
Release files / pysftp_ng-0.4.1.tar.gz
| Download URL | pysftp_ng-0.4.1.tar.gz |
|---|---|
| Size | 44.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a2feea0c722a0c1617aec29399181b87c5f4df1fca414d1355d55f2b8bf5b30d
|
|
BLAKE2b-256 checksum How to use checksums |
f7ed8d2297874b36f5c873744e7742798ee655826993dd225a4dbabe409cc859
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.
Transparency logRelease files / pysftp_ng-0.4.1-py3-none-any.whl
| Download URL | pysftp_ng-0.4.1-py3-none-any.whl |
|---|---|
| Size | 22.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e433f1b2f18ae8ce48469a808803c73a92a2cf6bca35db6e9bb9261078341c14
|
|
BLAKE2b-256 checksum How to use checksums |
0ba0b4a457a2abfaa732da6af4bd8f1ca4a93427098e6f8c7af49ceb7858a6cc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.
Transparency logSecurity for pysftp-ng 0.4.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for pysftp_ng-0.4.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.