Skip to content

Commit

Permalink
Retry on BrokenPipeError (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
xytxytxyt authored Aug 28, 2024
1 parent 463d722 commit e679620
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions reconnecting_ftp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ def mlst(connection: ftplib.FTP, filename: str, facts: Optional[List[str]] = Non

class Client:
"""
Reconnect to the FTP server if the connection has been closed.
The current working directory is cached in between the sessions. When you re-connect, it changes first to
Reconnect to the FTP server if the connection has been closed.
The current working directory is cached in between the sessions. When you re-connect, it changes first to
the last available CWD.
"""

Expand Down Expand Up @@ -158,7 +158,8 @@ def __wrap_reconnect(self, method: Callable[[ftplib.FTP], T]) -> T:
assert self.connection is not None, "Expected connect() to either raise or create a connection"
return method(self.connection)

except (ConnectionRefusedError, ConnectionAbortedError, socket.timeout, socket.gaierror, socket.herror,
except (BrokenPipeError, ConnectionRefusedError, ConnectionAbortedError,
socket.timeout, socket.gaierror, socket.herror,
ftplib.error_temp, EOFError) as err:
if self.connection is not None:
self.connection.close()
Expand Down

0 comments on commit e679620

Please sign in to comment.