Unable to download the large files using pysftp

Issue - Unable to download the large files using pysftp

I am trying to put the file from local to target sftp using pysftp.
I have a file >500 MB to download using sftp connection.
I tried the following pysftp code and getting Error: <class ‘socket.error’>. Socket is closed

with pysftp.Connection(dest_host, port=dest_port, username=abcd, private_key=target_key_path, private_key_pass=1234, cnopts=cnopts) as target_sftp
target_sftp.put(local_file)

However, the same code is able to download the file that has below 18mb size.

Normally a .put is considered an upload.

Is this the same code? I ask because it looks like
“target_sftp.put(local_file)” is not indented inside the “with”. As a
consequence the connection would be opened and then closed before the
.put runs, producing the “socket is closed” error, because the
connection is closed.

Indent the .put line and try again.

Cheers,
Cameron Simpson cs@cskk.id.au