#coding:utf-8
import paramiko
#创建一个连接的实例
ssh = paramiko.SSHClient()
#我们需要设定一个白名单
#know_hosts 访问受信任列表
know_hosts = paramiko.AutoAddPolicy()
ssh.set_missing_host_key_policy(know_hosts)
#链接我们的远程服务器
ssh.connect(
hostname="192.168.1.249",
port=22,
username="root",
password="111111"
)
stdin, stdout, stderr = ssh.exec_command("mkdir zzz")
#关闭链接,释放内存
ssh.close()
###上传下载文件
#coding:utf-8
import paramiko
#创建一个连接的实例
ssh = paramiko.SSHClient()
#我们需要设定一个白名单
#know_hosts 访问受信任列表
know_hosts = paramiko.AutoAddPolicy()
ssh.set_missing_host_key_policy(know_hosts)
trans = paramiko.Transport(
sock = ("192.168.1.249", 22)
)
trans.connect(
username='root',
password="111111"
)
sftp = paramiko.SFTPClient.from_transport(trans)
sftp.put("D:\\zzz.txt","/root/zzz.txt")
sftp.get("/root/zzz.txt", "D:\\zzz.txt")
trans.close()