__init__.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #!/usr/bin/env python
  2. # -*- coding:utf8 -*-
  3. # $Id: __init__.py 1220 2013-04-22 14:47:16Z g.rodola $
  4. # ======================================================================
  5. # Copyright (C) 2007-2013 Giampaolo Rodola' <g.rodola@gmail.com>
  6. #
  7. # All Rights Reserved
  8. #
  9. # Permission is hereby granted, free of charge, to any person
  10. # obtaining a copy of this software and associated documentation
  11. # files (the "Software"), to deal in the Software without
  12. # restriction, including without limitation the rights to use,
  13. # copy, modify, merge, publish, distribute, sublicense, and/or sell
  14. # copies of the Software, and to permit persons to whom the
  15. # Software is furnished to do so, subject to the following
  16. # conditions:
  17. #
  18. # The above copyright notice and this permission notice shall be
  19. # included in all copies or substantial portions of the Software.
  20. #
  21. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  23. # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  25. # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  26. # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  27. # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  28. # OTHER DEALINGS IN THE SOFTWARE.
  29. #
  30. # ======================================================================
  31. """
  32. pyftpdlib: RFC-959 asynchronous FTP server.
  33. pyftpdlib implements a fully functioning asynchronous FTP server as
  34. defined in RFC-959. A hierarchy of classes outlined below implement
  35. the backend functionality for the FTPd:
  36. [pyftpdlib.ftpservers.FTPServer]
  37. accepts connections and dispatches them to a handler
  38. [pyftpdlib.handlers.FTPHandler]
  39. a class representing the server-protocol-interpreter
  40. (server-PI, see RFC-959). Each time a new connection occurs
  41. FTPServer will create a new FTPHandler instance to handle the
  42. current PI session.
  43. [pyftpdlib.handlers.ActiveDTP]
  44. [pyftpdlib.handlers.PassiveDTP]
  45. base classes for active/passive-DTP backends.
  46. [pyftpdlib.handlers.DTPHandler]
  47. this class handles processing of data transfer operations (server-DTP,
  48. see RFC-959).
  49. [pyftpdlib.authorizers.DummyAuthorizer]
  50. an "authorizer" is a class handling FTPd authentications and
  51. permissions. It is used inside FTPHandler class to verify user
  52. passwords, to get user's home directory and to get permissions
  53. when a filesystem read/write occurs. "DummyAuthorizer" is the
  54. base authorizer class providing a platform independent interface
  55. for managing virtual users.
  56. [pyftpdlib.filesystems.AbstractedFS]
  57. class used to interact with the file system, providing a high level,
  58. cross-platform interface compatible with both Windows and UNIX style
  59. filesystems.
  60. Usage example:
  61. >>> from pyftpdlib.authorizers import DummyAuthorizer
  62. >>> from pyftpdlib.handlers import FTPHandler
  63. >>> from pyftpdlib.servers import FTPServer
  64. >>>
  65. >>> authorizer = DummyAuthorizer()
  66. >>> authorizer.add_user("user", "12345", "/home/giampaolo", perm="elradfmw")
  67. >>> authorizer.add_anonymous("/home/nobody")
  68. >>>
  69. >>> handler = FTPHandler
  70. >>> handler.authorizer = authorizer
  71. >>>
  72. >>> server = FTPServer(("127.0.0.1", 21), handler)
  73. >>> server.serve_forever()
  74. [I 13-02-19 10:55:42] >>> starting FTP server on 127.0.0.1:21 <<<
  75. [I 13-02-19 10:55:42] poller: <class 'pyftpdlib.ioloop.Epoll'>
  76. [I 13-02-19 10:55:42] masquerade (NAT) address: None
  77. [I 13-02-19 10:55:42] passive ports: None
  78. [I 13-02-19 10:55:42] use sendfile(2): True
  79. [I 13-02-19 10:55:45] 127.0.0.1:34178-[] FTP session opened (connect)
  80. [I 13-02-19 10:55:48] 127.0.0.1:34178-[user] USER 'user' logged in.
  81. [I 13-02-19 10:56:27] 127.0.0.1:34179-[user] RETR /home/giampaolo/.vimrc completed=1 bytes=1700 seconds=0.001
  82. [I 13-02-19 10:56:39] 127.0.0.1:34179-[user] FTP session closed (disconnect).
  83. """
  84. import logging
  85. __ver__ = '1.2.0'
  86. __date__ = '2013-04-22'
  87. __author__ = "Giampaolo Rodola' <g.rodola@gmail.com>"
  88. __web__ = 'http://code.google.com/p/pyftpdlib/'
  89. def _depwarn(msg):
  90. """
  91. Force DeprecationWarning to be temporarily shown (it's been
  92. disabled by default starting from python 2.7 / 3.2), then
  93. re-set the default behavior.
  94. """
  95. import warnings
  96. orig_filters = warnings.filters[:]
  97. try:
  98. #warnings.simplefilter('default')
  99. warnings.resetwarnings()
  100. warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
  101. finally:
  102. warnings.filters = orig_filters