Python's network programming [5], BOOTP + TFTP + FTP, implements a simple File transfer process

Source: Internet
Author: User
Tags ftp file ftp client

bootp-tftp-ftp

Directory

    1. File transfer process
    2. Server establishment Process
    3. Client building Process

1 File transfer Process /File Transfer Flow

Using bootp,tftp,ftp three kinds of transport protocols, the client and server are established to achieve a simple file transfer process.

    1. The server initializes the operation, turns on 3 threads, runs BOOTP,TFTP,FTP's server separately, carries on the listening waits;
    2. Client initiates the BOOTP broadcast, requests the response, after receiving the server response, initiates the TFTP based on the IP and file name of the callback, initiates the Rrq file download, waits for the file transfer to complete, the client continues to use BOOTP to initiate the broadcast, and initiates the TFTP based on the callback information ( This uses the BOOTP - transmitted IP as the IPthat connects TFTP until the BOOTP broadcast is unresponsive ( Timeout), then end BOOTP and TFTP;
    3. According to the files downloaded by TFTP, read the contents of the files which need to be downloaded, use the FTP client to initiate login, request to download the corresponding files until the ftp file download is complete, exit FTP and client.

Note: Three kinds of transmission protocol implementation process can refer to the relevant reading at the end of the text, some of the contents such as file path and filename are hard-coded, follow-up can be modified.

2 Server Establishment Process /Server Setup

The main steps of server Setup are:

(1) Instantiate bootp,tftp,ftp three servers;

(2) Turn on three threads, run the server separately, and listen for a wait.

1  fromBOOTP. BootpserverImportBootpserver2  fromTftp.tftpserverImportTftpserver3  fromFtp.ftpserverImportFtp_server4 5 classcommunidemoserver ():6     def __init__(self):7SELF.BOOTP =Bootpserver ()8Self.tftp =Tftpserver ()9Self.ftp =Ftp_server ()Ten  One     defServer_start (self): A Self.bootp.start () - Self.tftp.start () - Self.ftp.start () the  -Server =Communidemoserver () -Server.server_start ()

3 Client Building Process /Client Setup

Client setup steps include:

(1) Instantiate bootp,tftp,ftp three servers;

(2) Set up a loop, open the BOOTP broadcast, wait for the message to obtain the IP and file name, open tftp download the corresponding file. After completion, the broadcasting request continues until the broadcast is not answered;

(3) Open the TFTP download file, get the file name that need to download, open ftp to download. End FTP when download is complete.

1  fromBOOTP. BootpclientImportbootpclient2  fromTftp.tftpclientImporttftpclient3  fromFtp.ftpclientImportftp_client4 5 classcommunidemoclient ():6     def __init__(self):7SELF.BOOTP =bootpclient ()8Self.tftp =tftpclient ()9Self.ftp =ftp_client ()Ten  One     defAction (self): A          whileTrue: -Recv =self.bootp.client_request () -             ifRecv isNone: the                 Print('= = = [BOOTP and fttp] Action Done') -                  Break -SELF.TFTP.SERVER_IP =Recv[0] -Self.tftp.readRequest (recv[1]) +Self.ftp.download (['etsw.b3']) -File_list = [] +         Try: AWith open ('tftp\\tftpclientfile\\copy-files4.rc') as F: atInfo_line =None -                  whileInfo_line! ="': -Info_line =F.readline () -info = Info_line.strip ('\ n'). Split (':') -                     ifInfo! = ["'] andInfo! = [' ']: -file_name = info[1] in                         iffile_name! ="'  andfile_name! =' ': -File_list.append (File_name.strip (' ')) to         exceptFilenotfounderror: +             Print('= = = [FTP] Download file no found') - exit () the self.ftp.download (file_list) *         Print('= = = [FTP] Exit') $ Panax NotoginsengClient =communidemoclient () -Client.action ()

Related reading

1. BOOTP theory

2. BOOTP Python implementations

3. TFTP theory

4. The Python implementation of TFTP

5. FTP theory

6. Python implementation of FTP server

7. Python Implementations of FTP clients

Python's network programming [5], BOOTP + TFTP + FTP, implements a simple File transfer process

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.