gpt4 book ai didi

python - 用于上传和下载的 PYSFTP 脚本

转载 作者:行者123 更新时间:2023-12-03 23:22:46 29 4
gpt4 key购买 nike

当我尝试连接时,我收到以下消息,需要一些帮助。我正在执行的脚本如下。关于如何解决此问题的任何建议?

此外,一旦我解决了这个问题,我就希望向此脚本添加监听功能,直到结果文件可用并从不同的远程目录下载它。

先感谢您

No hostkey for host mysftpserver.com found.
Exception AttributeError: "'Connection' object has no attribute
'_sftp_live'" in <bound method Connection.__del__ of <pysftp.Connection
object at 0x101d8cd50>> ignored

Process finished with exit code 0

脚本
import pysftp as sftp

def sftpExample():

try:
s = sftp.Connection(host='mysftpserver', port=1211, username='myusername', password='mypassword')

remotepath='/Orders/incoming/myfile.csv'
localpath='/Users/myusername/projects/order88.csv'
s.put(localpath,remotepath)

s.close()

except Exception, e:
print str(e)

sftpExample()

最佳答案

pysftp documentation和其他答案 Stack Overflow似乎也暗示可以通过设置 cnopts.hostkeys = None 来解决错误.

所以完整的代码类似于:

import pysftp
def sftpExample():
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
with pysftp.Connection('hostname', username='me', password='secret', cnopts=cnopts) as sftp:
sftp.put('/Users/myusername/projects/order88.csv','/Orders/incoming/myfile.csv') # upload file to public/ on remote
sftp.close()

sftpExample()

希望能帮助到你!

关于python - 用于上传和下载的 PYSFTP 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44856683/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com