简体   繁体   中英

Python module paramiko cannot connect as paramiko.Tranport((host,port)).connect(username = username, password = password)

This is an example which works fine on friend's computer:

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.' 

However I have the following problem.

>>> 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

I have googled a lot of hours, tried different version (Arch Linux 64-bit/Windows 7 64-bit, python 2.7 32/64-bit, python 2.6 32-bit, paramiko 1.7.6, pycrypto 2.0.1/2.1/2.2 but nothing helped. I want to program a simple sfpt client for automatic downloading and deleting files but I am really baffled. If anyone could help me I would be very grateful. Thanks.

Can you try this and let me know how it goes:

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()

Is your friend running it on a Linux box? Are you running it on a Windows machine?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM