-
Notifications
You must be signed in to change notification settings - Fork 0
/
ftp.py
37 lines (26 loc) · 1.02 KB
/
ftp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""FTP module."""
import os
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
DEFAULT_PORT = 2121
DEFAULT_MAX_CONS = 256
STORAGE_BANNER: str = os.getenv('STORAGE_BANNER') or 'Hello'
STORAGE_HOST: str = os.getenv('STORAGE_HOST') or ''
STORAGE_PORT: int = int(os.getenv('STORAGE_PORT') or DEFAULT_PORT)
STORAGE_MAX_CONS: int = int(os.getenv('STORAGE_MAX_CONS') or DEFAULT_MAX_CONS)
STORAGE_MAX_CONS_PER_IP: int = int(os.getenv('STORAGE_MAX_CONS_PER_IP') or 5)
def main() -> None:
"""FTP runner."""
authorizer = DummyAuthorizer()
authorizer.add_anonymous('storage/', perm='elradfmwMT')
ftp_handler = FTPHandler
ftp_handler.authorizer = authorizer
ftp_handler.banner = STORAGE_BANNER
address = (STORAGE_HOST, STORAGE_PORT)
server = FTPServer(address, ftp_handler)
server.max_cons = STORAGE_MAX_CONS
server.max_cons_per_ip = STORAGE_MAX_CONS_PER_IP
server.serve_forever()
if __name__ == '__main__':
main()