1
votes

Hi im try to test my app ftp on python over app engine.

In local works with ftp but when i try to connect:

ftp://rebus-v5-prod.appspot.com:443 or ftps://rebus-v5-prod.appspot.com:443

Shows me:

Status: Connection established, waiting for welcome message... Error: Connection closed by server

My code:

import os
from backend import upload_jobs
from firebase.firebase import Firebase

if not bool(os.getenv('CLOUD',False)):
    from dotenv import load_dotenv
    load_dotenv(verbose=True)
    print('LOAD ENV',os.getenv('VERSION'))
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer

Firebase()
class HandleFTP(FTPHandler):
    def on_file_received(self, file):
        upload_jobs(file)
    def on_connect(self):
        print(self.remote_ip)

class Autorizer(DummyAuthorizer):
    def validate_authentication(self, username, password, handler):
        print(username,password,handler)

def main():
    # Instantiate a dummy authorizer for managing 'virtual' users
    authorizer = Autorizer()

    # Define a new user having full r/w permissions and a read-only
    # anonymous user
    authorizer.add_user('user', '12345', './files', perm='elradfmwMT')
    #authorizer.add_anonymous(os.getcwd())

    # Instantiate FTP handler class
    handler = HandleFTP
    handler.authorizer = authorizer
    # Define a customized banner (string returned when client connects)
    handler.banner = "pyftpdlib based ftpd ready."
    # Specify a masquerade address and the range of ports to use for
    # passive connections.  Decomment in case you're behind a NAT.
    # handler.masquerade_address = '151.25.42.11'
    handler.passive_ports = range(60000, 65535)

    # Instantiate FTP server class and listen on 0.0.0.0:2121
    address = ('', int(os.environ.get('PORT', 2121)))
    server = FTPServer(address, handler)

    # set a limit for connections
    server.max_cons = 256
    server.max_cons_per_ip = 5

    # start ftp server
    server.serve_forever()
    server.handle_write()


if __name__ == '__main__':
    main()

App engine YML

runtime: python
env: flex
entrypoint: python app.py

service: default

runtime_config:
  python_version: 3

automatic_scaling:
  min_num_instances: 1
  max_num_instances: 15
  cool_down_period_sec: 180
  cpu_utilization:
    target_utilization: 0.6

resources:
  cpu: 1
  memory_gb: 0.5
  disk_size_gb: 10

network:
  forwarded_ports:
    - 2121/tcp
1
Where have you defined a service that listens for connections on port 443? Your service is on port 2121. Also, I do not believe that FTP over port 443 will work. The Google Front End (GFE) expects the HTTP(S) protocol on port 443. The last time I checked App Engine Flexible (03/2019) did not support FTP at all. forwared_ports only works when you use the target instance's IP address, you cannot use ...appspot.com domain names. - John Hanley

1 Answers

0
votes

You're not forwarding port 443 to your app:

network:
  forwarded_ports:
    - 443/tcp

In addition, incoming traffic from outside your network is not allowed through the Google Cloud Platform firewalls. After you have specified port forwarding in your app.yaml file, you must add a firewall rule that allows traffic from the ports you want opened.

You can specify a firewall rule in the Networking Firewall Rules page in the Google Cloud Platform Console