使用 python 从 SFTP 拉取文件
from msilib.schema import Directory
import pysftp
import os
import glob
import fnmatch
from datetime import date, timedelta
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
myHostname = 'sftp.mmm.com'
myUsername = 'uuuu'
myPassword = 'pass'
with pysftp.Connection(host=myHostname, username=myUsername, password=myPassword, cnopts=cnopts) as sftp:
print("Connection Success")
remotefilepath='/REPORTING/test.zip'
localfilepath='Z:\\data\\sftp_data\\'
sftp.get(remotefilepath,localfilepath)
大家好 我一直在使用上面的代码从SFTP提取文件并保存在本地 但是我遇到了以下错误
chan = t.open_session( AttributeError:“NoneType”对象没有属性“open_session”
请告知
from msilib.schema import Directory
import pysftp
import os
import glob
import fnmatch
from datetime import date, timedelta
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
myHostname = 'sftp.mmm.com'
myUsername = 'uuuu'
myPassword = 'pass'
with pysftp.Connection(host=myHostname, username=myUsername, password=myPassword, cnopts=cnopts) as sftp:
print("Connection Success")
remotefilepath='/REPORTING/test.zip'
localfilepath='Z:\\data\\sftp_data\\'
sftp.get(remotefilepath,localfilepath)
Hi All
I have been using above code to pull the file from SFTP and save locally
However i am getting below error
chan = t.open_session(
AttributeError: 'NoneType' object has no attribute 'open_session'
Please advise
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当
with
语句结束,打印结束后,连接自动关闭。这就是with
的用途。更改为简单脚本或缩进脚本的其余部分,使其位于
with
内:When the
with
statement ends, after the print, the connection is automatically closed. That's whatwith
is for. Either change to a simpleor indent the rest of the script so it's inside the
with
: