After the server receives the connection request, it waits for the client to send a single status code. Server = socketserver.ThreadingTCPServer(ip_port, MyFtpServer) # Open Serviceġ.4.2 When the server enters the listening state, the client initiates a connection request. # Creating concurrent server-side objects Recv_data = (cmd_len).decode( ' utf-8 ') # Receive client data if recv_data.upper() = " Q ": # The client offered to disconnect break # Resolve, process client commands data_analy.syntax_analysis(recv_data, self.request, commom_obj) :return Return false Disconnected on behalf of clientĬmd_len = struct.unpack( ' i ' ,cmd_len_pack) # Get command length to prevent glue
:param commom_obj:Data objects required for program execution :param data_analy:Object responsible for parsing, executing client commands
After successful login, receive commands from clients and process them
PYTHON SIMPLEFTP SERVER REGISTRATION
Login.py: Authentication registration module for user registration, login authentication.ĭataAnalysis.py: A command parsing module responsible for parsing and executing client-side commands.įileOpertion.py: Read and write files.Data sending, data receiving.ĭb: Stores the user_pwd.db file for user information (username, password, total FTP directory space, used space, etc.)ġ.4.1 Program startup file FTPserver.py, program startup into a listening state.The core code is as follows: class MyFtpServer(socketserver.BaseRequestHandler):ĭef handle(self): # Rewrite handle Method,Handle socket request print(f " Connection fromDisconnected " )ĭef run_ftp_server(self,data_analy,commom_obj): server sideġ.1 The directory structure is as follows:Īpp: The main logical directory of the program, which has four modules: If there are any deficiencies, please forgive me.) 1. (I am a novice bird, for development specifications, interface design is completely unknown, is completely at will, entertainment.Blogging is mainly about recording your own learning. Learn to use struct to solve TCP sticky packages. Learn to use socketserver to achieve concurrent processing of multiple clients.Ģ.
Client: Windows 7 python-3.6.2 pycharm-2018