本文整理汇总了Python中pyftpdlib.servers.FTPServer.close方法的典型用法代码示例。如果您正苦于以下问题:Python FTPServer.close方法的具体用法?Python FTPServer.close怎么用?Python FTPServer.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyftpdlib.servers.FTPServer
的用法示例。
在下文中一共展示了FTPServer.close方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FTPd
# 需要导入模块: from pyftpdlib.servers import FTPServer [as 别名]
# 或者: from pyftpdlib.servers.FTPServer import close [as 别名]
class FTPd(threading.Thread):
def __init__(self, root_dir, address=None, timeout=0.001, dtp_handler=None):
threading.Thread.__init__(self)
self.__flag = threading.Event()
self.__timeout = timeout
authorizer = DummyAuthorizer()
authorizer.add_anonymous(root_dir)
handler = FTPHandler
handler.authorizer = authorizer
if dtp_handler is not None:
handler.dtp_handler = dtp_handler
self.server = FTPServer(address, handler)
def start(self):
self.__flag.clear()
threading.Thread.start(self)
self.__flag.wait()
def run(self):
self.__flag.set()
while self.__flag.is_set():
self.server.serve_forever(timeout=self.__timeout, blocking=False)
self.server.close_all()
self.server.close()
def stop(self):
self.__flag.clear()
self.join()
示例2: FTPListener
# 需要导入模块: from pyftpdlib.servers import FTPServer [as 别名]
# 或者: from pyftpdlib.servers.FTPServer import close [as 别名]
class FTPListener(threading.Thread):
"""
Simple thread to run the FTP Server
"""
def __init__(self, user=DEFAULT_USER, pwd=DEFAULT_PWD, port=DEFAULT_FTP_PORT, addr=DEFAULT_FTP_ADDR):
"""
Constructor
"""
self.user = user
self.pwd = pwd
self.port = port
self.addr = addr
threading.Thread.__init__(self)
def run(self):
"""
Starts the FTP server
"""
authorizer = DummyAuthorizer()
authorizer.add_user(self.user, self.pwd, ".", perm="elradfmw")
handler = OneTimeFTPHandler
handler.authorizer = authorizer
self.server = FTPServer((self.addr, self.port), handler)
self.server.serve_forever()
def stop(self):
"""
Stops the FTP server
"""
if self.server is not None:
self.server.close()