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 52 53 54 55 56 57 58 59 60 61 62
|
from pyftpdlib.handlers import FTPHandler from pyftpdlib.servers import FTPServer from pyftpdlib.authorizers import DummyAuthorizer import configparser,os,sys
def getVariable():
global user ,password ,path ,port user = str(config.get('FTP', 'user')) password = str(config.get('FTP', 'password')) path = str(config.get('FTP', 'path')) port = config.get('FTP', 'port') print("###############################################################") print("# [FTP]") print("# user="+user+"\n"+"# password="+password+"\n"+"# port"+port+"\n"+"# path"+path) print("###############################################################\n")
global config
config = configparser.ConfigParser() os.chdir(os.path.abspath(sys.path[0])) filename = 'config.ini' iniExists=os.path.exists(os.path.join(os.path.abspath(sys.path[0]),'config.ini')) print(filename) print(iniExists) if iniExists == False: with open(filename, mode='w') as file_ini: file_ini.write("[FTP]\n") file_ini.write("#ftp用户\n") file_ini.write("user=ftp\n") file_ini.write("#密码\n") file_ini.write("password=1\n") file_ini.write("#端口号\n") file_ini.write("port=23\n") file_ini.write("#路径\n") file_ini.write("path="+os.path.dirname(__file__))
config.read(filename, encoding='utf-8') getVariable()
authorizer = DummyAuthorizer() authorizer.add_user(user, password, path, perm='elradfmwM') handler = FTPHandler handler.authorizer = authorizer
server = FTPServer(('0.0.0.0', str(port)), handler) server.serve_forever()
|