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
Prev Previous commit
Next Next commit
Rename 'connection' object to 'client' for clarity
  • Loading branch information
jstorrs committed Jun 22, 2023
commit e4208066d950e09c75a9b002863758732692d340
10 changes: 5 additions & 5 deletions pooch/downloaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,12 +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.SSHClient()
connection.load_system_host_keys()
client = paramiko.SSHClient()
client.load_system_host_keys()
sftp = None
try:
connection.connect(hostname=parsed_url["netloc"], port=self.port, username=self.username, password=self.password, allow_agent=self.allow_agent)
sftp = connection.open_sftp()
client.connect(hostname=parsed_url["netloc"], port=self.port, username=self.username, password=self.password, allow_agent=self.allow_agent)
sftp = client.open_sftp()
sftp.get_channel().settimeout = self.timeout
if self.progressbar:
size = int(sftp.stat(parsed_url["path"]).st_size)
Expand All @@ -485,7 +485,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