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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#创建一个ssh的客户端,用来连接服务器
|
|
|
|
|
ssh = paramiko.SSHClient()
|
|
|
|
|
#创建一个ssh的白名单
|
|
|
|
|
know_host = paramiko.AutoAddPolicy()
|
|
|
|
|
#加载创建的白名单
|
|
|
|
|
ssh.set_missing_host_key_policy(know_host)
|
|
|
|
|
|
|
|
|
|
#连接服务器
|
|
|
|
|
ssh.connect(
|
|
|
|
|
hostname = "192.168.43.28",
|
|
|
|
|
port = 22,
|
|
|
|
|
username = "chan",
|
|
|
|
|
password = "H7N9UFOXC001203"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
#执行命令
|
|
|
|
|
stdin,stdout,stderr = ssh.exec_command("python tcpcloudrecv.py")
|
|
|
|
|
#stdin,stdout,stderr = ssh.exec_command("mkdir RRR")
|
|
|
|
|
#stdin 标准格式的输入,是一个写权限的文件对象
|
|
|
|
|
#stdout 标准格式的输出,是一个读权限的文件对象
|
|
|
|
|
#stderr 标准格式的错误,是一个写权限的文件对象
|
|
|
|
|
print(stdout.read().decode())
|
|
|
|
|
ssh.close()
|