Registry / http-networking / fs-sshfs

fs-sshfs

JSON →
library1.0.2pypypiunverified

fs-sshfs is a PyFilesystem2 extension that allows you to treat a remote SSH server's filesystem as a local `fs.FS` object, leveraging Paramiko for SSH connectivity. The current version is 1.0.2, and it receives updates as needed, particularly for compatibility with its core `paramiko` dependency, ensuring robust and secure remote file access.

pip install fs-sshfs
INSTALL
IMPORT
SIG · FS-SSHFS
F
fs-sshfs
http-networkingpythonv1.0.2
Install
3.4s avg
Import
Disk
45MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 42.4MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 3.4s · import 0.000s · 43MB
45MB installed
● package 45MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SSHFS
from fs.sshfs import SSHFS
from fs.sshfs import SSHFS

This quickstart demonstrates how to connect to a remote SSH server using `fs-sshfs` and list the contents of its root directory. It uses environment variables for secure credential handling and includes `paramiko.AutoAddPolicy` for simplified host key management during development. For production, a more secure host key policy is recommended.

import os from fs_sshfs import SSHFS from paramiko import AutoAddPolicy # Set these environment variables or replace with actual values # For password authentication: export SSH_HOST='your_host' SSH_USER='your_user' SSH_PASSWORD='your_password' # For key-based authentication: export SSH_HOST='your_host' SSH_USER='your_user' SSH_PKEY_PATH='/path/to/your/key' host = os.environ.get('SSH_HOST', '') user = os.environ.get('SSH_USER', '') password = os.environ.get('SSH_PASSWORD') pkey_path = os.environ.get('SSH_PKEY_PATH') port = int(os.environ.get('SSH_PORT', 22)) if not host or not user: print("Please set SSH_HOST and SSH_USER environment variables.") exit(1) # Configure SSH key if path is provided pkey = None if pkey_path: try: from paramiko import RSAKey, Ed25519Key, ECDSAKey, DSSKey # Attempt to load common key types; more robust error handling might be needed try: pkey = RSAKey.from_private_key_file(pkey_path) except Exception: pass try: pkey = Ed25519Key.from_private_key_file(pkey_path) except Exception: pass try: pkey = ECDSAKey.from_private_key_file(pkey_path) except Exception: pass try: pkey = DSSKey.from_private_key_file(pkey_path) except Exception: pass if not pkey: raise ValueError("Could not load PKEY from path") print(f"Using SSH key from: {pkey_path}") except Exception as e: print(f"Warning: Could not load SSH key from {pkey_path}: {e}") print("Falling back to password or no authentication if key fails.") pkey = None try: with SSHFS( host=host, user=user, passwd=password, port=port, pkey=pkey, # AutoAddPolicy is convenient for development but insecure for production missing_host_key_policy=AutoAddPolicy(), ) as remote_fs: print(f"Successfully connected to {host} as {user}") print("Listing root directory of the remote filesystem:") # Check if root is accessible and list contents if remote_fs.exists('/'): for info in remote_fs.scandir('/'): print(f" {info.name} ({'directory' if info.is_dir else 'file'})") else: print(" Root directory '/' does not exist or is inaccessible.") except Exception as e: print(f"Error connecting or listing remote files: {e}") print("Please ensure SSH_HOST, SSH_USER, and either SSH_PASSWORD or SSH_PKEY_PATH are set correctly.") print("Also, verify the SSH server is running and accessible.")
Debug
Known issues
breakingExplicit support for Paramiko 3 was added in `fs-sshfs` v1.0.2. If you are using an older version of `fs-sshfs` (prior to 1.0.2) with `paramiko` v3.x, you may encounter compatibility issues or unexpected behavior due to API changes in Paramiko.
fix
Upgrade `fs-sshfs` to version 1.0.2 or newer: `pip install --upgrade fs-sshfs`. Alternatively, pin your `paramiko` version to `<3.0` if `fs-sshfs` cannot be upgraded.
affects: <1.0.2
gotchaSSH host key verification can prevent connections if the remote host's key is not present in the local `known_hosts` file or if a strict policy is configured, leading to `SSHException` errors.
fix
Configure `missing_host_key_policy` in the `SSHFS` constructor. For development, `paramiko.AutoAddPolicy()` can be used (but is not recommended for production). For production, use `paramiko.WarningPolicy()` or `paramiko.RejectPolicy()` after pre-populating `~/.ssh/known_hosts`.
affects: All versions
gotcha`fs-sshfs` instances establish and hold SSH connections. It is crucial to properly close these connections to release system resources, especially in long-running applications or when opening multiple connections.
fix
Always use `SSHFS` as a context manager (`with SSHFS(...) as remote_fs:`), which automatically calls `close()` upon exiting the `with` block. Alternatively, manually call `remote_fs.close()` when you are finished with the filesystem object.
affects: All versions
Upgrade
Version history
1.0.2latest on PyPI · released Aug 17, 2023
Audit
Dependencies
paramikorequiredCore dependency for SSH/SFTP client functionality.
Agent activity
14 hits · last 30 days
node
14
Resources
fs-sshfs — pip install fs-sshfs · libregistry