Skip to content
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

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

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
15 changes: 11 additions & 4 deletions pooch/downloaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,18 @@ 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))
client = paramiko.SSHClient()
sftp = None
try:
connection.connect(username=self.username, password=self.password)
sftp = paramiko.SFTPClient.from_transport(connection)
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(
hostname=parsed_url["netloc"],
port=self.port,
username=self.username,
password=self.password,
)
sftp = client.open_sftp()
sftp.get_channel().settimeout = self.timeout
if self.progressbar:
size = int(sftp.stat(parsed_url["path"]).st_size)
Expand All @@ -484,7 +491,7 @@ def callback(current, total):
else:
sftp.get(parsed_url["path"], output_file)
finally:
connection.close()
client.close()
if sftp is not None:
sftp.close()

Expand Down
Loading