我的需求:
接入交换机执行命令:dis dev ma,得到SN序列号
然后设置一个remote_file,值为SN
remote_file = sn + ".cfg"
print(remote_file)
comware.Transfer('ftp', '10.0.100.254', 'remote_file', 'test.cfg', user='ftp', password='Ftp@123456')
最后使用comware.Transfer函数,将remote_file文件下载下来,现在在最后一步卡住了,前面使用print(remote_file)已经是210235xxxx.cfg了,但是在执行comware.Transfer时始终都是向ftp服务器请求remote_file的文件名。所以comware.Transfer函数可以将前面的remote_file内容赋予给Transfer函数里的remote_file么?
(0)
最佳答案
Comware自动化脚本特性及函数定义,comware.Transfer函数无法自动将字符串变量 remote_file
的值解析为参数,您的代码需要直接传递变量名而非字符串。以下是正确修改方案:
错误写法:comware.Transfer(..., 'remote_file', ...)
📌 问题:将 'remote_file'
作为字符串传递,函数会直接请求名为 remote_file
的文件,而非变量 remote_file
的值(如 210235xxxx.cfg
)。
正确写法:
移除引号,直接传递变量:
comware.Transfer('ftp', '10.0.100.254', remote_file, 'test.cfg', user='ftp', password='Ftp@123456')
✅ 作用:将变量 remote_file
的值(如 210235xxxx.cfg
)作为远程文件名传递给函数。
确认变量值:
在 Transfer
调用前添加打印语句验证文件名:
print("Downloading file:", remote_file) # 应输出如 "210235xxxx.cfg"
comware.Transfer('ftp', '10.0.100.254', remote_file, 'test.cfg', ...)
FTP服务器检查:
remote_file
值完全匹配的文件(如 210235xxxx.cfg
)。comware.Transfer
的 remotefile
参数需为 字符串变量(如 remote_file
)或 具体文件名(如 '210235xxxx.cfg'
),不能是未赋值的字符串 'remote_file'
。remote_file = sn + ".cfg" # 例如:210235xxxx.cfg
print("Download target:", remote_file) # 验证文件名
# 使用变量值传递远程文件名 ↓
comware.Transfer('ftp', '10.0.100.254', remote_file, 'test.cfg', user='ftp', password='Ftp@123456')
执行此修正后,函数将正确请求FTP服务器上的 210235xxxx.cfg
文件并下载为本地 test.cfg
。
(0)
好的,谢谢
亲~登录后才可以操作哦!
确定你的邮箱还未认证,请认证邮箱或绑定手机后进行当前操作
举报
×
侵犯我的权益
×
侵犯了我企业的权益
×
抄袭了我的内容
×
原文链接或出处
诽谤我
×
对根叔社区有害的内容
×
不规范转载
×
举报说明
好的,谢谢