Skip to main content

pysftp-ng

CI PyPI Python Docs

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.

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())

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 Ed25519Key or AgentKey, as private_key.
  • Default keys. With no password or key given, pysftp-ng tries ~/.ssh/id_rsa, id_ecdsa and id_ed25519 in OpenSSH's order and uses the first one the server accepts. 0.2.9 only looked for id_rsa and id_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-dss key, 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 the paramiko logger, including your application's.
  • Windows paths. put_r and put_d build 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. walktree sends one listing request per directory instead of one stat per entry.
  • Path traversal. If a server returns a file name that would land outside the target directory, such as ../../.bashrc, get_r, get_d and walktree skip it with a warning.
  • Smaller fixes. New CnOpts.timeout option. The username falls back to the OS user when LOGNAME isn't set, as on Windows. ConnectionException has a readable message.

Compatibility

  • The public API of pysftp 0.2.9 is kept: same names, arguments and return values. The deprecated log and ciphers arguments still work and emit a DeprecationWarning.
  • 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.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pysftp-ng 0.3.2
File Size Uploaded Provenance Actions
pysftp_ng-0.3.2.tar.gz 37.8 kB With provenance Details for pysftp_ng-0.3.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pysftp-ng 0.3.2
File Interpreter ABI Platform Actions
pysftp_ng-0.3.2-py3-none-any.whl Python 3 none any Details for pysftp_ng-0.3.2-py3-none-any.whl

Total release size: 58.7 kB

Release files / pysftp_ng-0.3.2.tar.gz

Download URL pysftp_ng-0.3.2.tar.gz
Size 37.8 kB
Tags Source
SHA-256 checksum
How to use checksums
be248e52d2295e2b1c41adabfc1280fe297fbe4d392e027c769ff8db98b61dbe
BLAKE2b-256 checksum
How to use checksums
18a56432570a63f3bb2a71f1e7bde1fd0fbc68b38c7ee843d71d577832a1d104
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 log

Release files / pysftp_ng-0.3.2-py3-none-any.whl

Download URL pysftp_ng-0.3.2-py3-none-any.whl
Size 20.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1bdcdaaa232917e846bd942e606ed1d49b88bbfa149abaff3aeea8ee76442fe0
BLAKE2b-256 checksum
How to use checksums
0806e867d414405091ba50fbba1d247a7d0c19ac0866705d1c7b8915099481cb
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 log

Security for pysftp-ng 0.3.2

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.

Select from 2 files

Attestation for pysftp_ng-0.3.2.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 log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page