首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何访问亚马逊EC2上的pyftpdlib FTPS服务器?

如何访问亚马逊EC2上的pyftpdlib FTPS服务器?
EN

Stack Overflow用户
提问于 2015-12-08 13:10:47
回答 1查看 2.4K关注 0票数 1

我试图使用Python pyftpdlib在我的Ubuntu EC2实例上创建一个简单的FTPS服务器。

以下是文档中的直接代码:

代码语言:javascript
复制
#!/usr/bin/env python

"""
An RFC-4217 asynchronous FTPS server supporting both SSL and TLS.
Requires PyOpenSSL module (http://pypi.python.org/pypi/pyOpenSSL).
"""

from pyftpdlib.servers import FTPServer
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.contrib.handlers import TLS_FTPHandler
import os


def main():
    authorizer = DummyAuthorizer()
    authorizer.add_user('ubuntu', '*****', os.getcwd(), perm='elradfmw')
    authorizer.add_anonymous('.')
    handler = TLS_FTPHandler
    handler.certfile = 'keycert.pem'
    handler.authorizer = authorizer
    handler.masquerade_address = '52.23.244.142'
    # requires SSL for both control and data channel
    handler.tls_control_required = True
    handler.tls_data_required = True
    handler.passive_ports = range(60000, 60099)
    server = FTPServer(('', 21), handler)
    server.serve_forever()

if __name__ == '__main__':
    main()

当我在我的亚马逊EC2实例上运行脚本时,当我试图使用FileZilla远程连接时,我得到:

代码语言:javascript
复制
Status: Connecting to 52.23.244.142:21...
Status: Connection established, waiting for welcome message...
Response:   220 pyftpdlib 1.4.0 ready.
Command:    AUTH TLS
Response:   234 AUTH TLS successful.
Status: Initializing TLS...
Status: Verifying certificate...
Command:    USER ubuntu
Status: TLS/SSL connection established.
Response:   331 Username ok, send password.
Command:    PASS *****
Response:   230 Login successful.
Command:    OPTS UTF8 ON
Response:   501 Invalid argument.
Command:    PBSZ 0
Response:   200 PBSZ=0 successful.
Command:    PROT P
Response:   200 Protection set to Private
Command:    OPTS MLST type;perm;size;modify;unix.mode;unix.uid;unix.gid;
Response:   200 MLST OPTS type;perm;size;modify;unix.mode;unix.uid;unix.gid;
Status: Connected
Status: Retrieving directory listing...
Command:    PWD
Response:   257 "/" is the current directory.
Command:    TYPE I
Response:   200 Type set to: Binary.
Command:    PASV
Response:   227 Entering passive mode (52,23,244,142,174,172).
Command:    MLSD
Response:   150 File status okay. About to open data connection.
Error:  Connection timed out
Error:  Failed to retrieve directory listing

我想我漏掉了什么。我能得到帮助吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-08 15:20:53

  1. 服务器必须在对PASV命令的响应中显示其外部IP地址。相反,您将在EC2专用网络中显示一个内部IP地址,FileZilla显然无法连接到该地址。 而FileZilla可以解决这个问题: 服务器发送带有不可路由地址的被动回复。使用服务器地址代替。

其他FTP客户端(如Windows命令行ftp.exe)不能.

使用handler.masquerade_address配置外部IP地址:

handler.masquerade_address = '52.23.244.142‘

  1. FileZilla无法连接到端口50048 (195个<< 8+ 128)。您可能还没有打开EC2防火墙中FTP被动模式端口范围内的端口。 请参阅在Amazon服务器上设置FTP (特别是最好的答案中的“步骤2:打开EC2实例上的FTP端口”一节)。 为了避免打开整个非特权端口范围,请将FTP服务器限制为使用handler.passive_ports的较小端口范围: handler.passive_ports =范围(60000,60099)

有关一般信息,请参阅我关于与FTP被动(和主动)连接模式相关的网络设置的文章。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34156779

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档