import paramiko
ssh=paramiko.SSHClient() #创建ssh对象
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy) #允许连接不在know_kosts文件中的主机
#连接服务器 ssh.connect(hostname="19.25.19.205",port=1984,username="1510qwert",password="niuzai007@xo.com") while True: cmd=input(">>: ").strip() if not cmd:continue
    #执行命令 stdin,stdout,stderr=ssh.exec_command(cmd) print(ssh.exec_command(cmd)) result=stdout.read()#获取结果 print(result.decode("utf-8")) ssh.close()#关闭链接

 上传下载

import  paramiko
transport=paramiko.Transport(("192.168.1.205",1984))
transport.connect(username="houge1510",password="007@xo.com")
sftp=paramiko.SFTPClient.from_transport(transport)
sftp.put(r"D:\boy_S\1期\day09\01.py","/tmp/01.py") #上传操作
sftp.get("/tmp/01.py",r"D:\boy_S\1期\day09\0100.py")#下载操作
transport.close()