繁体   English   中英

GCE 上的 FTP 服务器无法连接

[英]FTP server on GCE doesn't connect

我正在尝试在 Google Cloud Engine VM 中运行 FTP 服务器,但即使在编写了必要的防火墙规则后我也无法连接到它。

我正在通过 python 运行 FTP 服务器:

from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
import os
from google.cloud import storage

class MyHandler(FTPHandler):
    def on_file_received(self, file):
        storage_client = storage.Client.from_service_account_json(os.getenv('GCS_WORKER_CREDENTIALS'))
        bucket = storage_client.get_bucket(os.getenv('GCS_BUCKET'))
        blob = bucket.blob(file[5:]) # strip leading /tmp/
        blob.upload_from_filename(file)
        #os.remove(file)

def run_server():
    authorizer = DummyAuthorizer()
    authorizer.add_user(os.getenv('FTP_USER'), os.getenv('FTP_PASSWD'), os.getenv('FTP_PATH'), perm=os.getenv('FTP_PERMISSIONS'))
    handler = MyHandler

    handler.authorizer = authorizer
    handler.masquerade_address = os.getenv('VM_EXTERNAL_IP')
    handler.passive_ports = range(60000, 60999)
    handler.timeout = 300
    handler.banner = 'Welcome to GCP-FTP.'
    handler.max_login_attempts = 3
    handler.use_sendfile = False

    server = FTPServer(("127.0.0.1", os.getenv('FTP_PORT')), handler)
    server.serve_forever()

if __name__=='__main__':
    run_server()

我尝试在端口 21 和 6999 上运行 FTP 但都给了我同样的错误。

当我运行服务器时,一切看起来都很好

root@poc-worker:/home/xxxxxxxxx/etl-cloud# python3 run_ftp_server.py 
[I 2021-06-15 12:55:16] concurrency model: async
[I 2021-06-15 12:55:16] masquerade (NAT) address: 130.211.xxx.xxx
[I 2021-06-15 12:55:16] passive ports: 60000->60998
[I 2021-06-15 12:55:16] >>> starting FTP server on 127.0.0.1:21, pid=1021 <<<

GC中的网络规则:

Name: ftp-allow
Type: Incoming
Destination: Apply to all
IP: 0.0.0.0/0
tcp: 60000-60999,6999,21
Action: Allow
Priority: 1000
Network: default

当我测试网络规则时,它还告诉我一切都应该没问题,我不确定我在这里做错了什么,任何帮助将不胜感激。

我发现了问题,如此处所述: Google Cloud Compute Engine refusing connections 尽管有防火墙规则

我将服务器绑定到仅本地连接的 127.0.0.1,将其绑定到 0.0.0.0 解决了问题

server = FTPServer(("127.0.0.1", os.getenv('FTP_PORT')), handler)

变成

server = FTPServer(("0.0.0.0", os.getenv('FTP_PORT')), handler)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM