0

This is the code I have taken from the docs of pyftpdlib library. I get ftp locally but not able to access it from outside. I am using wifi from mobile and so I think I am behind NAT.

I have tried hours on getting this working but nothing worked. Tried other similar question solutions but they had only some theory and that lead me to no result.

I need that I can connect with my ftp using my ip from outside network.

I have added firewall rules on port21 to allow all connections but it made no change. Also an explanation like which IP to be used when will be much helpful. Other related questions did no help to me.

import os

from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer

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

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

    # Instantiate FTP handler class
    handler = FTPHandler
    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 = 'My Public IP checked online'
    handler.passive_ports = range(20, 65535)

    # Instantiate FTP server class and listen on 0.0.0.0:2121
    address = ('0.0.0.0', 21)
    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()

if __name__ == '__main__':
    main()

Logs from cmd
In browser I connect by using ftp://X.X.X.X or ftp://localhost , here X.X.X.X is my prvate ip.
Problem is how to make it available on my public ip so I can access from any device.
On Public IP it gets timeout, I am on wifi.

[I 2020-05-11 20:27:13] concurrency model: async
[I 2020-05-11 20:27:13] masquerade (NAT) address: X.X.X.X
[I 2020-05-11 20:27:13] passive ports: 20->65534
[I 2020-05-11 20:27:13] >>> starting FTP server on 0.0.0.0:21, pid=9072 <<<
[I 2020-05-11 20:28:07] 127.0.0.1:5054-[] FTP session opened (connect)
[I 2020-05-11 20:28:07] 127.0.0.1:5054-[anonymous] USER 'anonymous' logged in.
[I 2020-05-11 20:28:07] 127.0.0.1:5054-[anonymous] CWD C:\Users\Dell\Desktop\ftp_server 250
  • Check your IP address first. If you have one from the private networks, you definitely have NAT https://en.wikipedia.org/wiki/Private_network – James Z May 09 '20 at 15:02
  • @JamesZ Yes, I confirm that I am behind NAT. – Kush Choudhary May 09 '20 at 15:23
  • @JamesZ I am not able to get it working even then. Not knowing what values to be changed and what ip to be passed in the address or handler.masquerade_address field. Tried randomly, no luck. – Kush Choudhary May 09 '20 at 15:24
  • What exact problem/error are you getting when trying to access the server? Show us some logs. – Martin Prikryl May 11 '20 at 06:36
  • @MartinPrikryl After running the script. I open browser and goto my private ip address which works as expected(ftp server). But with any other device It gets timeout or no result at all. Reason is I need to make this ftp available on my public ip. I am using wifi from my mobile. So I am behind a NAT, any comments on how can or what possible settings do I need to change? my OS is windows. – Kush Choudhary May 11 '20 at 14:52
  • You didn't answer my question and you didn't provide any logs. Though if you do not have a network connectivity to the server, you actually do not have a programming question. You should head to [su] or [sf]. – Martin Prikryl May 11 '20 at 14:53
  • @There are no logs, My script only shows connected when connecting with local address. I put them in 2 min. – Kush Choudhary May 11 '20 at 14:54
  • @MartinPrikryl Problem is with my script, What address to be used or which configs to be used is causing this. – Kush Choudhary May 11 '20 at 14:55
  • @MartinPrikryl All that I have is added to question. thanks. – Kush Choudhary May 11 '20 at 15:02
  • What about client-side logs? – Martin Prikryl May 11 '20 at 15:04

0 Answers0