Python pysftp.put raises “No such file” exception although file is uploaded

后端 未结 1 1378
北荒
北荒 2021-01-15 05:29

I am using pysftp to connect to a server and upload a file to it.

cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
self.sftp = pysftp.Connection(host=self.se         


        
相关标签:
1条回答
  • 2021-01-15 06:15

    From the described behaviour, I assume that the file is removed very shortly after it is uploaded by some server-side process.

    By default pysftp.Connection.put verifies the upload by checking a size of the target file. If the server-side processes manages to remove the file too fast, reading the file size would fail.

    You can disable the post-upload check by setting confirm parameter to False:

    self.sftp.put(localpath=self.filepath+filename, remotepath=filename, 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 Paramiko (which pysftp uses internally), see:
    Paramiko put method throws "[Errno 2] File not found" if SFTP server has trigger to automatically move file upon upload

    0 讨论(0)
提交回复
热议问题