connection droped issue with paramiko while uploading huge files code example
Example: connection droped issue with paramiko while uploading huge files
with paramiko.Transport((server, 22)) as transport:
transport.default_window_size = paramiko.common.MAX_WINDOW_SIZE // 2
transport.packetizer.REKEY_BYTES = pow(2,
40)
transport.packetizer.REKEY_PACKETS = pow(2,
40)
transport.connect(username=username, password=pw)
with paramiko.SFTPClient.from_transport(transport) as sftp:
sftp.get_channel().in_window_size = 2097152
sftp.get_channel().out_window_size = 2097152
sftp.get_channel().in_max_packet_size = 2097152
sftp.get_channel().out_max_packet_size = 2097152
files = sftp.listdir()
files = list(filter(lambda x: x.endswith(".zip"), files))
print(files)
if len(files) > 2:
for f in files:
target = str(dst / f)
print(f"Downloading {f} to {target}")
sftp.get(f, target)
for f in files:
sftp.remove(f)