过滤 pyftpdlid 中的目录列表

Filter directory listing in pyftpdlid

在pyftpdlid how to filter the list of directorys returned based on specific conditions,我想隐藏一些目录,files.I觉得可能和'def ftp_LIST(self, path):'方法有关。我已经尝试了多种变体,但其中 none 似乎有效。有什么想法吗?

我认为你需要:

  • AbstractedFS 导出 class。
  • 重新实现其 listdir method
  • AbstractedFS 的实现分配给 FTPHandler.abstracted_fs
class FilteredFS(AbstractedFS):
    def listdir(self, path):
        files = os.listdir(path)
        # filter as you need
        return files

handler = FTPHandler
# ...
handler.abstracted_fs = FilteredFS
server = FTPServer(('', 21), handler)
server.serve_forever()