Fix retry handling on SFTP upload failures
@@ -471,16 +471,21 @@ def get_file(
def _put_file(host: "Host", filename_or_io, remote_location):
attempts = 1
+ last_e = None
+ while attempts < 4:
try:
with get_file_io(filename_or_io) as file_io:
sftp = _get_sftp_connection(host)
sftp.putfo(file_io, remote_location)
+ return
except OSError as e:
- if attempts > 3:
- raise
logger.warning(f"Failed to upload file, retrying: {e}")
attempts += 1
+ last_e = e
+
+ if last_e is not None:
+ raise last_e
def put_file(
