登录ssh,显示文件,切换目录
import paramiko client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client.connect(‘172.16.66.132‘, 22, username=‘user‘, password=‘password ‘, timeout=4) stdin, stdout, stderr = client.exec_command(‘ls -l‘) for std in stdout.readlines(): print std, stdin, stdout, stderr = client.exec_command(‘cd /etc;pwd‘) for std in stdout.readlines(): print std, client.close()
输出结果
[[email protected] glpi_switch_ocs]# python ssh.py total 12 -rw-r--r-- 1 root root 1542 Oct 21 16:31 ceph.log -rw-r--r-- 1 root root 1645 Oct 21 14:43 release.asc -rw-r--r-- 1 root root 26 Nov 23 10:00 test /etc [[email protected] glpi_switch_ocs]#
时间: 2024-11-11 16:14:31