Python ftp ideas

Source: Internet
Author: User
Tags reflection

Experience
0) generally in the more formal class of the constructor. There will be a Verify_args function to validate the incoming parameters. Especially for system parameters.
1) and the system, in fact, the back is probably a function of the name
For example: Python server.py start #start就是server. py inside a function, usually inside a class
2) So Verify_args is going to use reflection to judge
If hasattr (server, ' Start '):
Start = getattr (server, ' start ')
3) comparison in the constructor, the direct Self.start () write dead practice. The advantage of this method is that it can be called more than start, and can call similar help,restrart and so on. With strong scalability. That can be raised to shrink
4) According to this idea, you can add a Help method to the class, the system to pass the parameter, the Python server.py helps


tricks
1) When thinking about ideas, first ensure that the ' premise ' can be achieved, do not the cart before the horse.
2) Edge write edge test to verify that the logic is successful, even if the server side is the same, initially define a client that can feedback results to connect. You can use print to make a placeholder, in order to display logic for authentication
3) Encoding: First write logic, first placeholder
4) If you can have a clear grouping, such as one after the first (processing send, receive processing), preferably sub-function writing
5) If there is interaction, must ensure that the corresponding good, Requires step-by-step verification. If you do not write a step, you need to write a step of party B, and then test the interaction.
6) Do not complicate, must be simplified, simple!!! Don't complicate the problem until you are not.


Weighs 0 to one
I. Start-up phase
1) Create all folders.
2) First things to enter the configuration file, configuration good Ip_port
3) Create main.py within Modules folder, create Logichandler class inside. First Pass
4) Enter the bin and create the entrance. Entrance to create a logical class object
Two. Main logic design phase
Logical design. Since there are no objects to interact with, it is said that this class is draped in an object-oriented face process. Design with process-oriented thinking
From a server-side perspective
1) Enter the Help parameter to display the assistance information
2) Enter the start parameter to start the server
3) After the successful start, if there is a client link up, accept the link and enter the verification phase, receive the client's account password
4) Read the User.cfg file under the DB to verify, send the verification failure notification code and the success prompt
5) If successful, save the user name, save the user home directory path, enter the command interaction phase.
6) Write command interaction functions, receive commands that begin with various function names, and use reflection to distribute the commands.
7) write various functions in turn
8) The distribution function is initially defined as start (), is really responsible for starting the entire server, due to the need for concurrency, need to socketserver, so
To create a serverhandler.py in Modlues, define the Serverhandler class. Same, pass first, test logic

Third, enter the Serverhandler class
1) Enter the handle function because the specified handle function is to be overwrite. First the price while the loop of true is received
2) Design the protocol header, {' Action ': ' auth ', ' username ': ' Ziyi ', ' password ': ' 123 '}, that is, the first 1024 bytes received is this JSON string, you can use the "" "string in the function to be annotated

Write client because communication test function is required
1) or Verify_args, because it involves the system passing IP and port. Return Ip_port for links
2) define make_connection for receiving Ip_port parameter linked server. Note that Self.sock is here to initialize the best

Four, write the server interactive function.
Writing Client interaction functions
1) The desired situation is c=clienthandler ()
C.interactive ()
2) Client interaction function The first step is to invoke the authentication function

Five, write the client authentication function
1) Divide two function Authenticate,get_auth_result, the former obtains input inputs, the latter obtains the server feedback.
2) The server receives processing messages from the client and prints them first.
Side Write side verification: Don't rush to print out the first printing is not as envisaged. If you don't do that, you'll waste a lot of time behind the problem.

Six, back to the client interactive function continues to improve.
1) The idea is to get input from the input function and distribute it to other functions of the class after processing.
2) First is the upload function, the file upload function

Seven, write the client file upload function.
1) generate a JSON string, the action key is specified as ' upload ', write the sending section first, receive a portion of the server after acceptance to write
2) then write the server corresponding upload service function.

Python ftp ideas

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.