返回顶部

欢迎来到菜鸟大明儿哥的博客

我们一起交流学习,不断提升自我

Ansible scp Python脚本

 

 

 


import os
import paramiko

def RemoteScp(host_ip, host_port, host_username, host_password, remote_path, local_path):
scp = paramiko.Transport((host_ip, host_port))
scp.connect(username=host_username, password=host_password)
sftp = paramiko.SFTPClient.from_transport(scp)
try:
remote_files = sftp.listdir(remote_path)
for file in remote_files:
local_file = local_path + file
remote_file = remote_path + file
sftp.get(remote_file, local_file)
except IOError:
return ("remote_path or local_path is not exist")
scp.close()


if __name__ == '__main__':
host_ip = '192.168.1.100'     --源端IP
host_port = 22    --源端SSH端口
host_username = 'root'  --源端用户名
host_password = '12345678'  --源端密码
remote_path = '/orabak/baktmp/'  --源端存放备份集路径
local_path = '/bak/scorabak/'    --目的端路径
RemoteScp(host_ip, host_port, host_username, host_password, remote_path, local_path)

posted @ 2021-09-23 15:14  菜鸟大明儿哥  阅读(341)  评论(0编辑  收藏  举报