-
Notifications
You must be signed in to change notification settings - Fork 9
/
entrypoint.py
51 lines (41 loc) · 1.61 KB
/
entrypoint.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import os, random, string
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
length = 8
chars = string.ascii_letters + string.digits
random.seed = (os.urandom(1024))
FTP_ROOT = '/home'
USER = os.getenv('USER', 'user')
PASSWORD = os.getenv('PASSWORD', ''.join(random.choice(chars) for i in range(length)))
HOST = os.getenv('HOST','0.0.0.0')
PORT = 21
PASSIVE_PORTS = '3000-3010'
ANONYMOUS = os.getenv('ANONYMOUS', False)
def main():
user_dir = os.path.join(FTP_ROOT, USER)
if not os.path.isdir(user_dir):
os.mkdir(user_dir)
authorizer = DummyAuthorizer()
authorizer.add_user(USER, PASSWORD, user_dir, perm="elradfmw")
if ANONYMOUS:
authorizer.add_anonymous("/ftp_root/nobody")
handler = FTPHandler
handler.authorizer = authorizer
handler.permit_foreign_addresses = True
passive_ports = map(int, PASSIVE_PORTS.split('-'))
handler.passive_ports = range(passive_ports[0], passive_ports[1])
print('*************************************************')
print('* *')
print('* Docker image: mikatux *')
print('* https://github.com/mikatux/ftp-server *')
print('* *')
print('*************************************************')
print('SERVER SETTINGS')
print('---------------')
print "FTP User: ",USER
print "FTP Password: ",PASSWORD
server = FTPServer((HOST, PORT), handler)
server.serve_forever()
if __name__ == '__main__':
main()