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)

  • 相关阅读:
    性能测试相关
    centos7 设置定时器 crond
    大杀器Bitset
    树形DP
    双线程DP
    状态压缩DP
    斜率优化DP
    01分数规划
    二分和三分
    uva11549 Floyd判圈法
  • 原文地址:https://www.cnblogs.com/zhm1985/p/15324313.html
Copyright © 2011-2022 走看看