giampaolo / pyftpdlib

Extremely fast and scalable Python FTP server library
MIT License
1.68k stars 264 forks source link

starting a ftpd server for an IP associated with a NIC that hasn't been connected yet #452

Closed marcDesm closed 6 years ago

marcDesm commented 6 years ago

On a PC that's just been powered up, and using a NIC connected to an embedded system that's about the get powered on, the PC NIC is configured (with Win7) , but since it's never gotten a "ping" from the embedded system, it seems the launching pyftpdlib fails (see below). If I then power up the embedded system, after a few seconds, it fails to netboot from my PC, but it has sent some low level "pings" , enough to apparently place the NIC in some different state (to Window 7's liking). So that if I try again to start pyftpdlib , THEN it succeeds. I don't have this problem when I run the standalone WFTPD tool. Is there a work around? What's the difference? Thanks.

Here's output when it fails

_Process Process-5: Traceback (most recent call last): File "multiprocessing\process.py", line 258, in _bootstrap File "multiprocessing\process.py", line 114, in run File "ethernet.py", line 31, in ftpd File "site-packages\pyftpdlib-1.5.4-py2.7.egg\pyftpdlib\servers.py", line 114, in init File "site-packages\pyftpdlib-1.5.4-py2.7.egg\pyftpdlib\ioloop.py", line 1018, in bind_afunspecified error: [Errno 10049] The requested address is not valid in its context

Here's good output, as a sanity check. It does work is I use 127.0.0.1

INFO:pyftpdlib:>>> starting FTP server on 127.0.0.1:21, pid=3616 <<< INFO:pyftpdlib:concurrency model: async INFO:pyftpdlib:masquerade (NAT) address: None INFO:pyftpdlib:passive ports: None DEBUG:pyftpdlib:poller: 'pyftpdlib.ioloop.Select' DEBUG:pyftpdlib:authorizer: 'pyftpdlib.authorizers.DummyAuthorizer' DEBUG:pyftpdlib:handler: 'pyftpdlib.handlers.FTPHandler' DEBUG:pyftpdlib:max connections: 512 DEBUG:pyftpdlib:max connections per ip: unlimited DEBUG:pyftpdlib:timeout: 300 DEBUG:pyftpdlib:banner: 'pyftpdlib 1.5.4 ready.' DEBUG:pyftpdlib:max login attempts: 3

This is how I start it in my main program, as a subprocess that I can kill at anytime, ... proc = Process(target=ftpd, args=(ip,)) proc.start() ... proc.terminate() ... def ftpd(ip): authorizer = DummyAuthorizer() authorizer.add_anonymous(os.getcwd()) handler = FTPHandler handler.authorizer = authorizer authorizer.add_user('ba5020blue', 'test','C:\FMC_LOAD',perm="elr") server = FTPServer((ip, 21), handler) logging.basicConfig(level=logging.DEBUG) server.serve_forever()

marcDesm commented 6 years ago

On Monday I'll try: address = ("0.0.0.0", 21) # listen on every IP on my machine on port 21

marcDesm commented 6 years ago

Using IP address '0.0.0.0' solved the problem