1

有没有办法使用 Paramiko 作为 SFTP 连接到 sharefile.com?

例如,使用这种方法,我可以连接到 SFTP(我自己在 Linux 中创建的):

from paramiko import SSHConfig, SSHClient, AutoAddPolicy, AuthenticationException

def connect(self):
    for rec in self:

        with closing(SSHClient()) as ssh:
            ssh.set_missing_host_key_policy(AutoAddPolicy())
            try:
                login = rec.login_id
                ssh.connect(login.host, port=login.port, username=login.user, password=login.passwd)
            except socket.gaierror:
               raise ValidationError(_("Name or service '%s' not known") % (login.host))
            except AuthenticationException:
               raise Warning(_("Bad username or password"))                    
            with closing(ssh.open_sftp()) as sftp:
                #do something

但是,如果我尝试使用 fileshare.com 的登录信息进行连接,它就不起作用。在 fileshare.com 中,它说您可以通过两种方式连接:

安全性:标准(端口 21)或隐式 SSL/TLS(端口 990)
FTP 服务器:company.sharefileftp.com
用户名:用户名或 username_id
密码:(您的 ShareFile 密码)

因此,如果我尝试使用端口 990 进行连接,我将得到连接超时(一段时间后)或此错误:

File "/usr/lib/python2.7/dist-packages/paramiko/client.py", line 306, in connect
    t.start_client()
File "/usr/lib/python2.7/dist-packages/paramiko/transport.py", line 465, in start_client
    raise e
SSHException: Error reading SSH protocol banner

我能够连接到它的唯一方法是使用 Ubuntu 内置的 GUI 来连接 FTP,使用:

ftp//:user@company.sharefileftp.com

如果我使用sftp,它将无法连接(我猜它使用默认端口 22)

我也尝试从终端连接:

ftp user@company.sharefileftp.com
Name or service not known
sftp -oPort=990 user@company.sharefileftp.com
ssh_exchange_identification: Connection closed by remote host
Couldn't read packet: Connection reset by peer
4

1 回答 1

4

安全 FTP(基于TLS/SSL的 FTP )不是SFTP

SFTP 通过 SSH 运行。

您不能使用 Paramiko 连接到 FTP,既不是普通的 FTP,也不是通过 TLS/SSL。

使用ftplibFTP_TLS中的类在 Python 中通过 TLS/SSL 进行 FTP。

于 2015-08-03T09:49:02.100 回答