1. 程式人生 > >python3 paramiko模組

python3 paramiko模組

#通過paramiko模組連線主機執行bash命令

import paramiko
hostname = '192.168.254.24'
port = 22
username = 'root'
password = 'root'
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname=hostname,port=port,username=username,password=password)
stdin, stdout, stderr 
= ssh.exec_command("ls -ltr") print(stdout.read().decode('utf-8')) #通過paramiko模組連線主機上傳 import paramiko hostname = '192.168.254.24' port = 22 username = 'root' password = 'root' t=paramiko.Transport((hostname,port)) t.connect(username=username,password=password) sftp = paramiko.SFTPClient.from_transport(t) sftp.put(r
'C:\Users\fengzi\Desktop\Linux.xmind', '/root/aaa.xmind') sftp.close() #通過paramiko模組連線主機下載 import paramiko hostname = '192.168.254.24' port = 22 username = 'root' password = 'root' t=paramiko.Transport((hostname,port)) t.connect(username=username,password=password) sftp = paramiko.SFTPClient.from_transport(t) sftp.get(
'/root/test3.yml', r'C:\Users\fengzi\Desktop\test3.yml') sftp.close()