我的环境:win10(64bit)、python3.6.6(64bit)
-
安装paramiko
pip install paramiko
2、建立ssh连接
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(ssh_server,ssh_port,ssh_user,ssh_password)
-
执行命令
示例:
#检查有没有文件夹
stdin,stdout,stderr = ssh.exec_command(‘find /home/www‘)
result = stdout.read().decode(‘utf-8’)
如果有查询到就会返回值否则为空
-
断开连接
ssh.close()
-
使用捕获异常
try:
…
…
Except Exception as e:
print(e)
闻道有先后 术业有专攻
From: shaynerain.com
By: Shaynerain