Skip to content
Draft
Changes from all commits
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
15 changes: 9 additions & 6 deletions pysus/api/ftp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,15 @@ async def download(
) -> pathlib.Path:
"""Download a remote file locally, optionally reporting progress."""

async def _fetch():
try:
self.ftp.voidcmd("NOOP")
except BrokenPipeError:
await self.connect()
def _noop():
self.ftp.voidcmd("NOOP")

try:
await to_thread.run_sync(_noop)
except BrokenPipeError:
await self.connect()

def _fetch():
total_size = self.ftp.size(str(file.path)) or 0
current_size = 0

Expand All @@ -203,7 +206,7 @@ def _write_and_callback(chunk):
self.ftp.retrbinary(f"RETR {file.path}", _write_and_callback)
return output

return await _fetch()
return await to_thread.run_sync(_fetch)

@staticmethod
def _line_parser(
Expand Down