发布网友 发布时间:2022-04-23 15:40
共1个回答
热心网友 时间:2022-04-18 08:12
实例1:
#!/usr/bin/python
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("172.16.1.3",22,"root","333333")
stdin, stdout, stderr = ssh.exec_command("df -h")
print stdout.readlines()
ssh.close()
实例2:
#!/usr/bin/python
import paramiko
t = paramiko.Transport(("172.16.1.2",322))
t.connect(username = "root", password = "222222")
sftp = paramiko.SFTPClient.from_transport(t)
remotepath='/opt/test.txt'
localpath='/opt/test.txt'
sftp.put(localpath,remotepath)
#sftp.get(remotepath, localpath)
t.close()