SSHException使用Paramiko Lib连接到sFTP时出错 - Python 3.4

时间:2016-02-04 10:40:22

标签: python python-3.x ssh sftp paramiko

我正在尝试连接到sFTP并传输文件但遇到SSHException错误。

我使用的是Python 3.4.3.7,64位

我正在使用paramiko库和SFTPClient协议:

import paramiko

transport = paramiko.Transport((host, port))
transport.connect(username = username, password = password)
sftp = paramiko.SFTPClient.from_transport(transport)
sftp.get(remote_path,local_path)
sftp.close()
transport.close()

我得到的错误是:

'Unable to connect to %s: %s' % (hostname, reason))
paramiko.ssh_exception.SSHException: Unable to connect to host: [WinError     10060] A connection attempt failed because the connected party did not properly   respond after a period of time, or established connection failed because connected host has failed to respond

我也尝试通过SSHClient协议连接,我得到了同样的错误。使用的代码是:

import os
import paramiko

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host, username=username, password=password)
sftp = ssh.open_sftp()
sftp.get(remote_path, local_path)
sftp.close()
ssh.close()

0 个答案:

没有答案