Description:
- Work with data via SFTP
Resources:
- [Fsspec Docs] https://filesystem-spec.readthedocs.io/en/stable/api.html?highlight=sftp#fsspec.implementations.sftp.SFTPFileSystem
- [Paramiko Docs] https://docs.paramiko.org/en/3.3/api/client.html#paramiko.client.SSHClient.connect
Environment variables
Section titled “Environment variables”This notebook reads its settings from environment variables. Set them before starting Jupyter:
SFTP_HOST: hostname of your SFTP serverSFTP_PORT: optional, defaults to22SFTP_USER: SFTP user nameSFTP_PRIVATE_KEY_PATH: path to that user’s private key file
Example 1
Section titled “Example 1”List contents of the filesystem via SSH
import os
from fsspec import filesystem
sftp_user = os.environ["SFTP_USER"]
# Extra keyword arguments are passed to paramiko's SSHClient.connect()fs = filesystem("sftp", host=os.environ["SFTP_HOST"], port=int(os.environ.get("SFTP_PORT", "22")), username=sftp_user, key_filename=os.environ["SFTP_PRIVATE_KEY_PATH"])
fs.ls(f"/home/{sftp_user}")Example 2
Section titled “Example 2”List contents of the filesystem via SFTP
import os
from fsspec.implementations.sftp import SFTPFileSystem
sftp_user = os.environ["SFTP_USER"]
sftp = SFTPFileSystem(host=os.environ["SFTP_HOST"], port=int(os.environ.get("SFTP_PORT", "22")), username=sftp_user, key_filename=os.environ["SFTP_PRIVATE_KEY_PATH"])
sftp.info(f"/home/{sftp_user}")ganymede is made by Eugo