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.
teamwk123/python/ssh3.py

26 lines
777 B

4 weeks ago
import paramiko
import sys
path = sys.argv[1]
#创建一个ssh的客户端用来连接服务器
ssh = paramiko.SSHClient()
#创建一个ssh的白名单
know_host = paramiko.AutoAddPolicy()
#加载创建的白名单
ssh.set_missing_host_key_policy(know_host)
#连接服务器
ssh.connect(
hostname = "192.168.43.114",
port = 22,
username = "chan",
password = "H7N9UFOXC001203"
)
#执行命令
stdin,stdout,stderr = ssh.exec_command("python3 tcpclient3.py "+path)
#stdin,stdout,stderr = ssh.exec_command("mkdir RRR")
#stdin 标准格式的输入,是一个写权限的文件对象
#stdout 标准格式的输出,是一个读权限的文件对象
#stderr 标准格式的错误,是一个写权限的文件对象
print(stdout.read().decode())
ssh.close()