【问题标题】:Specifying the port in a pysftp connection string is not straight forward在 pysftp 连接字符串中指定端口并不简单
【发布时间】:2019-04-24 12:27:46
【问题描述】:

这行得通:

cnopts = pysftp.CnOpts()
cnopts.hostkeys = None

with pysftp.Connection('ftpsite.com', username='xxx', password='xxx', cnopts=cnopts) as sftp:
    with sftp.cd('inbox'):             
    sftp.get('WinSCP.ini')  

但现在我想直接测试 ftp(端口 21),所以我添加了端口属性:

with pysftp.Connection('ftpsite.com', port=21 , username='xxx', password='xxx', cnopts=cnopts) as sftp:

现在我明白了:

异常:paramiko.ssh_exception.SSHException 消息:读取 SSH 协议横幅时出错

我很困惑……

【问题讨论】:

    标签: python pysftp


    【解决方案1】:

    SFTP 使用 SSH,所以它的端口是 22,而不是 21

    FTP 使用 21 端口

    就像错误所说,ssh异常。尝试使用 'port=22'

    来源:

    port 21     Yes, and SCTP   Assigned    Official    File Transfer Protocol (FTP) control (command)
    
    
    port 22     Yes, and SCTP   Assigned    Official    Secure Shell (SSH), secure logins, file transfers (scp, sftp) and port forwarding 
    

    wikipedia

    【讨论】:

    • 是的,你完全正确,ftp 是端口 21。Pysftp 默认为 22,所以如果你想测试一个 FTP,你需要在字符串中明确说明端口 21,但这证明比预期的要困难.
    • 所以,我不明白你的麻烦......请解释一下。你问为什么 1/ 有效,而不是 2/。我给了你答案。现在怎么了?
    • 我在指定端口 21 时收到此信息:异常:paramiko.ssh_exception.SSHException 消息:读取 SSH 协议横幅时出错,并且 pysftp 的文档没有明确给出参数的格式示例。
    • ?服务器是否打开并配置了 21 端口?我不了解您的用例,您想要什么,您拥有什么以及您期望什么。如果您希望人们花时间帮助您,请花时间解释
    【解决方案2】:

    pysftp 库仅使用 SFTP 协议进行通信,这与“普通”FTP 协议不同。因此,您看到的是当您的程序尝试在 SFTP 中与 FTP 服务器通信时出现的错误,并且不理解它返回的响应。

    【讨论】:

      猜你喜欢
      • 2011-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-27
      • 2015-06-02
      • 2016-12-30
      • 2014-06-11
      相关资源
      最近更新 更多