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