Skip to content

Use paramiko.SSHClient in SFTPDownloader (enables SSH agent authentication) #368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add allow_agent parameter to SFTPDownloader
  • Loading branch information
jstorrs committed Jun 22, 2023
commit 9240a3228f48a24a13840063fa9dac109eab8a76
9 changes: 6 additions & 3 deletions pooch/downloaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,15 @@ def __init__(
account="",
timeout=None,
progressbar=False,
allow_agent=False,
):
self.port = port
self.username = username
self.password = password
self.account = account
self.timeout = timeout
self.progressbar = progressbar
self.allow_agent = allow_agent
# Collect errors and raise only once so that both missing packages are
# captured. Otherwise, the user is only warned of one of them at a
# time (and we can't test properly when they are both missing).
Expand Down Expand Up @@ -453,11 +455,12 @@ def __call__(self, url, output_file, pooch):
The instance of :class:`~pooch.Pooch` that is calling this method.
"""
parsed_url = parse_url(url)
connection = paramiko.Transport(sock=(parsed_url["netloc"], self.port))
connection = paramiko.SSHClient()
connection.load_system_host_keys()
sftp = None
try:
connection.connect(username=self.username, password=self.password)
sftp = paramiko.SFTPClient.from_transport(connection)
connection.connect(hostname=parsed_url["netloc"], port=self.port, username=self.username, password=self.password, allow_agent=self.allow_agent)
sftp = connection.open_sftp()
sftp.get_channel().settimeout = self.timeout
if self.progressbar:
size = int(sftp.stat(parsed_url["path"]).st_size)
Expand Down