亚洲国产欧美一区二区三区f,亚洲A∨精品永久无码青草网,亚洲 暴爽 av人人爽日日碰,亚洲AV永久无码精心天堂久久_无码

系統城裝機大師 - 唯一官網:www.outletmksalestore.com!

當前位置:首頁 > 腳本中心 > python > 詳細頁面

Python 中 Paramiko 的使用實例

時間:2020-04-23來源:電腦系統城作者:電腦系統城

Paramiko : 是Python 用于控制liunx中文件的第三方庫,可創建文件,修改,刪除文件的內容等;

代碼實例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# -*- coding:utf-8 -*-
import paramiko
 
class ssh(object):
    def __init__(self,host,port,user,password):
        self.host = host
        self.port = port
        self.user = user
        self.password = password
        self.ssh_client = paramiko.SSHClient()
        self.ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        self.ssh_client.connect(self.host, self.port, self.user, self.password)
 
    #執行指令返回文本字符串
    def sftp_exec_command(self,command):
        arrconfiglist = [""]
        try:
            std_in, std_out, std_err = self.ssh_client.exec_command(command)
            for line in std_out:
                arrconfiglist.append(line.strip("\n"))
            del arrconfiglist[0]
            self.ssh_client.close()
            return arrconfiglist
        except Exception as e:
            print(e,"ssh ERROR")
        finally:
            self.ssh_client.close()
 
    #執行指令無返回
    def sftp_exec_norecommand(self,command):
        try:
            self.ssh_client.exec_command(command)
            self.ssh_client.close()
        except Exception as e:
            print(e,"ssh ERROR")
        finally:
            self.ssh_client.close()
 
'''
在別的項目中被調用使用如下方法
import ssh as ssh
 
if __name__ == '__main__':
    ssh.ssh().sftp_exec_command("--command information--")
'''
 
'''
if __name__ == '__main__':
    rect = ssh().sftp_exec_command("")
    print(rect)
'''

 

分享到:

相關信息

系統教程欄目

欄目熱門教程

人氣教程排行

站長推薦

熱門系統下載

亚洲国产欧美一区二区三区f,亚洲A∨精品永久无码青草网,亚洲 暴爽 av人人爽日日碰,亚洲AV永久无码精心天堂久久_无码 日本少妇又色又爽又高潮