Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
605 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.

See Question&Answers more detail:os

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

1 Reply

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...