[英]How do I access pyftpdlib FTPS server on Amazon EC2?
我正在嘗試使用Python庫pyftpdlib在Ubuntu Amazon EC2實例上創建一個簡單的FTPS服務器。
這是直接來自文檔的代碼:
#!/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()
當我在Amazon EC2實例上運行腳本並嘗試使用FileZilla進行遠程連接時,我得到:
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
我想我缺少了一些東西。 我可以幫忙嗎?
您的服務器必須在對PASV
命令的響應中顯示其外部IP地址。 您可以在EC2專用網絡中提供一個內部IP地址,FileZilla顯然無法連接到該內部IP地址。
盡管FileZilla可以解決該問題:
服務器發送了具有不可路由地址的被動答復。 改用服務器地址。
其他FTP客戶端(例如Windows命令行ftp.exe
)不能。
使用handler.masquerade_address
配置外部IP地址:
handler.masquerade_address = '52.23.244.142'
FileZilla無法連接到端口50048(195 << 8 + 128)。 您可能尚未在EC2防火牆的FTP被動模式端口范圍內打開端口。
請參閱在最佳答案中 在Amazon Cloud Server上設置FTP (特別是“步驟2:在您的EC2實例上打開FTP端口”部分 )。
為了避免打開整個非特權端口范圍,請使用handler.passive_ports
將FTP服務器限制為使用較小的端口范圍:
handler.passive_ports = range(60000, 60099)
有關一般信息,請參閱我的有關FTP被動(和主動)連接模式的網絡設置文章。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.