Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
643 views
in Technique[技术] by (71.8m points)

python - Paramiko put method throws "[Errno 2] File not found" if SFTP server has trigger to automatically move file upon upload

I'm calling the Paramiko sftp_client.put(locapath,remotepath) method

This is throwing the [Errno 2] File not found error below.

01/07/2020 01:12:03 PM - ERROR - [Errno 2] File not found
Traceback (most recent call last):
  File "file_transferTransferFiles.py", line 123, in main
  File "paramikosftp_client.py", line 727, in put
  File "paramikosftp_client.py", line 689, in putfo
  File "paramikosftp_client.py", line 460, in stat
  File "paramikosftp_client.py", line 780, in _request
  File "paramikosftp_client.py", line 832, in _read_response
  File "paramikosftp_client.py", line 861, in _convert_status

Having tried many of the other recommend fixes I found that the error is due to the server having an automatic trigger to move the file immediately to another location upon the file being uploaded.

I've not seen another post relating to this issue and wanted to know if anyone else has fixed this as the SFTP server is owned by a third party and not wanting to change trigger attributes.

The file actually uploads correctly, so I could catch the Exception and ignore the error. But I'd prefer to handle it, if possible.

question from:https://stackoverflow.com/questions/65833441/paramiko-upload-errors-errno-2

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Paramiko by default verifies a size of the uploaded file after the upload.

If the file is moved away immediately after upload, the check fails.

To avoid the check, set confirm parameter of SFTPClient.put to False.

sftp_client.put(localpath, remotepath, confirm=False)

I believe the check is redundant anyway, see
How to perform checksums during a SFTP file transfer for data integrity?


For a similar question about pysftp (what is a wrapper around Paramiko), see:
Python pysftp.put raises "No such file" exception although file is uploaded


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...