python调用nacos账号密码,Python脚本,使用私钥(如果可用)或用户名密码

嘿,丹尼,试着跟着斯内普。注意:键值来自配置yml是RSA私钥文件的完整路径(如:/home/user/.ssh/id_RSA)。在import paramiko

import StringIO

import yaml

try:

cfg=yaml.load(open("config.yml"))["local"]

paramiko.util.log_to_file('sftpin.log')

sftp = paramiko.Transport(cfg["host"], cfg["port"])

key_string = cfg["key"]

private_key = None

if key_string is not None:

f = open(key_string, 'r')

s = f.read()

not_really_a_file = StringIO.StringIO(s)

private_key = paramiko.RSAKey.from_private_key(not_really_a_file,

password=cfg["key_passwd"])

sftp.connect(username=cfg["user"],

password=cfg["pass"],

pkey=private_key)

sftp = paramiko.SFTPClient.from_transport(sftp)

print 'Connecting'

files = sftp.listdir(cfg["remote_outbox"])

print 'Listing Contents'

print files

print 'Getting Files'

for f in files:

remote = "%s%s" %(cfg["remote_outbox"], f)

local = "%s%s" %(cfg["local_inbox"], f)

try:

sftp.get(remote, local)

except IOError:

print "Failed to copy %s" % remote

print 'Job Completed'

finally:

sftp.close()

敬KG。在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值