码迷,mamicode.com
首页 > 其他好文 > 详细

use paramiko to connect remote server and execute command

时间:2018-09-20 01:16:53      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:set   missing   HCL   mis   exe   port   std   username   param   

#!/usr/bin/env python

import sys, paramiko

hostname = ‘‘
password = ‘‘
command = ‘ls‘

username = ""
port = 22

try:
    client = paramiko.SSHClient()
    client.load_system_host_keys()
    client.set_missing_host_key_policy(paramiko.WarningPolicy)

    client.connect(hostname, port=port, username=username, password=password)

    stdin, stdout, stderr = client.exec_command(command)
    print(stdout.read(), end=‘‘)

finally:
    client.close()

use paramiko to connect remote server and execute command

标签:set   missing   HCL   mis   exe   port   std   username   param   

原文地址:https://www.cnblogs.com/otfsenter/p/9678354.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!