小编Ami*_*are的帖子

尽管文件已上传,但 Python pysftp.put 会引发“没有此类文件”异常

我正在使用 pysftp 连接到服务器并向其上传文件。

cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
self.sftp = pysftp.Connection(host=self.serverConnectionAuth['host'], port=self.serverConnectionAuth['port'],
                              username=self.serverConnectionAuth['username'], password=self.serverConnectionAuth['password'], 
                              cnopts=cnopts)
self.sftp.put(localpath=self.filepath+filename, remotepath=filename)
Run Code Online (Sandbox Code Playgroud)

有时它没有错误,但有时它会正确放置文件,但会引发以下异常。该文件由服务器上运行的另一个程序读取和处理,因此我可以看到该文件在那里并且没有损坏

cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
self.sftp = pysftp.Connection(host=self.serverConnectionAuth['host'], port=self.serverConnectionAuth['port'],
                              username=self.serverConnectionAuth['username'], password=self.serverConnectionAuth['password'], 
                              cnopts=cnopts)
self.sftp.put(localpath=self.filepath+filename, remotepath=filename)
Run Code Online (Sandbox Code Playgroud)

我怎样才能防止异常?

python sftp pysftp

2
推荐指数
1
解决办法
3141
查看次数

标签 统计

pysftp ×1

python ×1

sftp ×1