在Windows下Python使用SSH若干事
在Windows下Python使用SSH若干事
#
缘由
叶子我最近折腾OpenSUSE,新本到了之后,实在懒得折腾多系统了,所以搞了虚拟机,OpenSUSE感觉还是不错的,在Windows下配合PuTTY(顺便说一下,一定要用英文版)真是……怎一个爽字了得。
咳咳,扯远了……于是,在ST3下,准备折腾一下,写个插件,写好脚本直接用SSH传到虚拟机去,然后远端执行……
顺带提一下,我偷懒装的WinPython……
折腾
先装ssh,直接用pip
pip install ssh
这货需要PyCrypto,会自动安装的,然后……一大堆我就木有仔细看,直接运行脚本了
#!/usr/bin/env python
import ssh
# New SSHClient
client = ssh.SSHClient()
# Default accept unknown keys
client.set_missing_host_key_policy(ssh.AutoAddPolicy())
# Connect
client.connect("192.168.17.128", port=22, username="xana", password='xxxxxxx')
# Execute shell remotely
stdin, stdout, stderr = client.exec_command("ls -alh")
print(stdout.read())
Ctrl+B……报错!
找不到Crypto……ssh要引用它,好么,仔细一看,site-packages下crypto文件夹改为Crypto,再来。
Ctrl+B……报错!python告诉我找不到Crypto.Random,我看了一下,包里还真没有……奇怪。
pip uninstall crypto
然后再来
pip install pycrypto
这次眼睛放雪亮了,看到Error了…… Unable to find vcvarsall.bat
,好吧,感情pycrypto这货居然还要编译,估计是为了效率?核心部分都用C写的啊……
google了一下, 这里 提到了解决方案,对于他的第二个方案装VS我倒是很简单,VS2013老早就装好了,算了一下,应该是VC110,打开 Lib/distuils/msvc9compiler.py
,找到 toolskey
,把赋值部分直接改成
toolskey = "VS110COMNTOOLS"
再次安装PyCrypto,编译成功,搞定。