zoukankan      html  css  js  c++  java
  • 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)

  • 相关阅读:
    组合模式
    迭代器模式
    模板方法模式
    外观模式
    适配器模式
    运行mysql时,提示Table ‘performance_schema.session_variables’ doesn’t exist
    idea maven 打包 引用本地jar
    centos7 安装redis
    centos7 防火墙
    linux 常用命令
  • 原文地址:https://www.cnblogs.com/zhm1985/p/15324313.html
Copyright © 2011-2022 走看看