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
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 42.4MB
glibcpy 3.10–3.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.")
Upgrade
Version history
1.0.2latest on PyPI · released Aug 17, 2023
Audit
Dependencies
paramikorequiredCore dependency for SSH/SFTP client functionality.