发布时间:2019-09-15 09:57:05编辑:auto阅读(2060)
installtion:
yum -y install python-devel
pip install paramiko
problem:
1.1 error: command ‘gcc’ failed with exit status 1
这是缺少python-devel软件包,安装即可
1.2 导入paramiko时报错: error: ‘module’ object has no attribute ‘HAVE_DECL_MPZ_POWM_SEC’
编辑 /usr/lib/python2.7/site-packages/Crypto/Util/number.py
把if _fastmath is not None and not _fastmath.HAVE_DECL_MPZ_POWM_SEC:
注释了
#if _fastmath is not None and not _fastmath.HAVE_DECL_MPZ_POWM_SEC:
use:
1.3 执行命令并将结果输出
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("某IP地址",22,"用户名", "口令")
stdin, stdout, stderr = ssh.exec_command("你的命令")
print stdout.readlines()
ssh.close()
1.4 下载远程文件
import paramiko
t = paramiko.Transport((“主机”,”端口”))
t.connect(username = “用户名”, password = “口令”)
sftp = paramiko.SFTPClient.from_transport(t)
remotepath=’/var/log/system.log’
localpath=’/tmp/system.log’
sftp.get(remotepath, localpath)
t.close()
1.5 上传文件
import paramiko
t = paramiko.Transport((“主机”,”端口”))
t.connect(username = “用户名”, password = “口令”)
sftp = paramiko.SFTPClient.from_transport(t)
remotepath=’/var/log/system.log’
localpath=’/tmp/system.log’
sftp.put(localpath,remotepath)
t.close()
上一篇: Python import同级modul
下一篇: 【python】 ConfigParse
47846
46395
37285
34736
29316
25974
24917
19952
19547
18031
5793°
6416°
5930°
5963°
7065°
5912°
5946°
6439°
6405°
7781°