-
Notifications
You must be signed in to change notification settings - Fork 0
/
ftpserver.py
36 lines (26 loc) · 962 Bytes
/
ftpserver.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
# System imports
import sqlite3 as db
import subprocess
import os,sys
# Package imports
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
# Local Imports
from static import IP_ADDR, PORT
def create_server():
authorizer = DummyAuthorizer()
conn = db.connect("main.db")
ftprootdir = str(os.getcwd()) + "/recv_img/"
user_details = conn.cursor().execute("SELECT * FROM login")
for user in user_details:
ftpuserrootdir = ftprootdir + user[0]
authorizer.add_user(user[0],user[1],ftprootdir, perm="elradfmw")
os.makedirs(ftpuserrootdir, exist_ok=True)
print("[ " + user[0] + " ]'s\t\t\tFTP_ROOT_DIRECTORY created :) ")
handler = FTPHandler
handler.authorizer = authorizer
server = FTPServer((IP_ADDR,PORT),handler)
server.serve_forever()
if __name__ == "__main__":
create_server()