You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
import paramiko
|
|
|
|
|
import time
|
|
|
|
|
#创建一个ssh的客户端,用来连接服务器
|
|
|
|
|
ssh = paramiko.SSHClient()
|
|
|
|
|
#创建一个ssh的白名单
|
|
|
|
|
know_host = paramiko.AutoAddPolicy()
|
|
|
|
|
#加载创建的白名单
|
|
|
|
|
ssh.set_missing_host_key_policy(know_host)
|
|
|
|
|
|
|
|
|
|
#连接服务器
|
|
|
|
|
ssh.connect(
|
|
|
|
|
hostname = "192.168.43.47",#你虚拟机的IP地址
|
|
|
|
|
port = 22,
|
|
|
|
|
username = "86157",#用户名
|
|
|
|
|
password = "qzy123456"#密码
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
#执行命令
|
|
|
|
|
stdin,stdout,stderr = ssh.exec_command("python C://Users//86157//Desktop//Test//tcpqzy.py")
|
|
|
|
|
#stdin,stdout,stderr = ssh.exec_command("mkdir RRR")
|
|
|
|
|
#stdin 标准格式的输入,是一个写权限的文件对象
|
|
|
|
|
#stdout 标准格式的输出,是一个读权限的文件对象
|
|
|
|
|
#stderr 标准格式的错误,是一个写权限的文件对象
|
|
|
|
|
#print(stdout.read().decode())
|
|
|
|
|
ssh.close()
|