embedding a python FTP server

48 views
Skip to first unread message

jhack...@gmail.com

unread,
Feb 4, 2015, 9:01:17 AM2/4/15
to pyft...@googlegroups.com
Hi all,
I'd like to embed a FTP server in a python process having its own "serve_forever" loop (i.e. can't call server.serve_forever() from the __main__ entry point)
What's the best way to do so using pyftpdlib?
Should I run it into a dedicated thread? What's about performances in this case (shared GIL)?
Thanks.
N.

Giampaolo Rodola'

unread,
Feb 4, 2015, 9:24:02 AM2/4/15
to pyft...@googlegroups.com
Yes, you should run server.serve_forever() in a separate thread.
The test suite provides something like this:
That class is useful because you can start() and stop() the FTP server (if you want). I recommend you copy and paste it and customize it depending on your needs (all the things you should care about are in the __init__ constructor).
I don't think there will be any major performance issue.

--
You received this message because you are subscribed to the "Python FTP server library" project group:
http://code.google.com/p/pyftpdlib/
To post to this group, send email to pyft...@googlegroups.com
To unsubscribe from this group, send email to pyftpdlib-...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/pyftpdlib
---
You received this message because you are subscribed to the Google Groups "Python FTP server library - Discussion group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyftpdlib+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

jhack...@gmail.com

unread,
Feb 4, 2015, 9:32:56 AM2/4/15
to pyft...@googlegroups.com
Thanks a lot for the example.

jhack...@gmail.com

unread,
Feb 4, 2015, 11:07:52 AM2/4/15
to pyft...@googlegroups.com
I just had a look to the code. Exactly what I was looking for. Thanks again.
I simply noticed something weird @ line 279 of the provide example (in FTPd.start).
The call to FTPd.__init__ does not match the FTPd.__init__ signature.
BTW, why do you need to "ensure the server can be started again"?



Giampaolo Rodola'

unread,
Feb 4, 2015, 11:14:44 AM2/4/15
to pyft...@googlegroups.com
You are right, that is an error and since I never restart the server (as in start(); stop(); start()) during tests I never noticed it (legacy code I suppose).


--
You received this message because you are subscribed to the "Python FTP server library" project group:
http://code.google.com/p/pyftpdlib/
To post to this group, send email to pyft...@googlegroups.com
To unsubscribe from this group, send email to pyftpdlib-...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/pyftpdlib
---
You received this message because you are subscribed to the Google Groups "Python FTP server library - Discussion group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyftpdlib+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jhack...@gmail.com

unread,
Feb 5, 2015, 1:08:41 PM2/5/15
to pyft...@googlegroups.com
There is one more thing I don't understand in the example: what is the aim of the mutex (i.e. self.__lock) in FTPd.run?
As far as I understand how a mutex work, the acquire/release sequence around self.__server.serve_forever is useless (there's only on thread executing FTPd.run).
Did I missed something? Something related to the underlying GIL?
Thanks for your help.



Giampaolo Rodola'

unread,
Feb 5, 2015, 1:13:44 PM2/5/15
to pyft...@googlegroups.com
Good question. My honest answer is that I put it there because I experienced what looked like synchronization issues between threads (experienced under the form of test failures). A long time passed since then and now I no longer (or rarely) experience those failures anymore so it may be possible that those mutexes are useless now.

--
You received this message because you are subscribed to the "Python FTP server library" project group:
http://code.google.com/p/pyftpdlib/
To post to this group, send email to pyft...@googlegroups.com
To unsubscribe from this group, send email to pyftpdlib-...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/pyftpdlib
---
You received this message because you are subscribed to the Google Groups "Python FTP server library - Discussion group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyftpdlib+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages