zoukankan      html  css  js  c++  java
  • Python Paramiko模块使用

    1 执行远程命令

     

    #!/usr/bin/python

    import paramiko

     

    ssh = paramiko.SSHClient()

    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

    ssh.connect("IP地址",22,"用户名", "口令")

    stdin, stdout, stderr = ssh.exec_command("你的命令")

    print stdout.readlines()

    ssh.close()

     

    2 上传文件到远程

     

    #!/usr/bin/python

    import paramiko

     

    t = paramiko.Transport(("IP地址",22))

    t.connect(username = "用户名", password = "口令")

    sftp = paramiko.SFTPClient.from_transport(t)

    remotepath='/tmp/test.txt'

    localpath='/tmp/test.txt'

    sftp.put(localpath,remotepath)

    t.close()

     

    3 从远程下载文件

     

    #!/usr/bin/python

    import paramiko

     

    t = paramiko.Transport(("IP地址",22))

    t.connect(username = "用户名", password = "口令")

    sftp = paramiko.SFTPClient.from_transport(t)

    remotepath='/tmp/test.txt'

    localpath='/tmp/test.txt'

    sftp.get(remotepath, localpath)

    t.close()

  • 相关阅读:
    链接收藏:bullet物理引擎不完全指南
    设计模式的六大原则
    链接错误 2038
    玄天宝录
    第二章 期中架构
    第一章 Linux基础
    13 代理与负载均衡基础
    12 LNMP搭建
    11 搭建博客
    10 Nginx模块介绍
  • 原文地址:https://www.cnblogs.com/s-seven/p/9307913.html
Copyright © 2011-2022 走看看