这是一个在朋友的电脑上运行良好的例子:
import paramiko
host = "157.178.35.134"
port = 222
username = "stackoverflow"
password = "e2fghK3"
transport = paramiko.Transport((host, port))
transport.connect(username = username, password = password)
sftp = paramiko.SFTPClient.from_transport(transport)
import sys
path = './file.testy' #server
localpath = '/home/iwtu/test'
sftp.put(localpath, path)
sftp.close()
transport.close()
print 'Upload done.'
但是我有以下问题。
>>> import paramiko
Warning (from warnings module):
File "C:\DevelopingTools\Python\lib\site-packages\Crypto\Util\randpool.py", line 40
RandomPool_DeprecationWarning)
RandomPool_DeprecationWarning: This application uses RandomPool, which is BROKEN in older releases. See http://www.pycrypto.org/randpool-broken
>>> host = '157.178.35.134'
>>> port = 222
>>> username = 'stackoverflow'
>>> password = 'e2fghK3'
>>> t = paramiko.Transport((host,port))
>>> t.connect(username = username, password = password)
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
t.connect(username = username, password = password)
File "C:\DevelopingTools\Python\lib\site-packages\paramiko\transport.py", line 989, in connect
self.start_client()
File "C:\DevelopingTools\Python\lib\site-packages\paramiko\transport.py", line 458, in start_client
raise e
EOFError
我已经搜索了很多小时,尝试了不同的版本(Arch Linux 64位/ Windows 7 64位,python 2.7 32/64位,python 2.6 32位,paramiko 1.7.6,pycrypto 2.0.1 /2.1/2.2但没有任何帮助。我想编写一个简单的sfpt客户端来自动下载和删除文件,但我真的很困惑。如果有人能帮助我,我会非常感激。谢谢。
答案 0 :(得分:2)
你可以尝试一下,让我知道它是怎么回事:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("157.178.35.13", username="stackoverflow", password="e2fghK3")
ftp=ssh.open_sftp()
path = './file.testy' #server
localpath = '/home/iwtu/test'
ftp.put(localpath, path)
ftp.close()
您的朋友是否在Linux机器上运行它? 你在Windows机器上运行它吗?