Python Socket TFTP protocol

Source: Internet
Author: User
Tags file transfer protocol

1. TFTP protocol Introduction

TFTP (Trivial file Transfer Protocol, simple Document Transfer Protocol)

is a protocol in the family of TCP/IP protocols for simple file transfer between client and server

Characteristics:

    • Simple
    • Low resource footprint
    • Suitable for passing small files
    • Suitable for on-LAN delivery
    • Port number is 69
    • Based on UDP implementation
2. TFTP download process

TFTP server listens on port 69th by default

When a client sends a "download" request (that is, a read request), it needs to send a 69 port to the server

If the server approves this request, it uses a new, temporary port for data transfer

When the server finds a file that needs to be present, it immediately opens the file and sends the data in the file to the client via the TFTP protocol.

If the total size of the file is large (for example, 3M), then the server is sent multiple times, each time it reads 512 bytes of data from the file.

Because the number of times sent can be many, so in order to let the client docking the received data to sort, so when the server sends the 512 bytes of data, there will be more than 2 bytes of data, used to store the ordinal number, and placed in front of 512 bytes of data, the sequence number is starting from 1

Because the file may not exist when the file needs to be downloaded from the server, the server will send an error message, in order to differentiate the service is sending the file content or the wrong message, so it uses 2 bytes to represent the function of the packet (called OpCode), and in the front of the ordinal

Note: 1. Packet format is in string form

2. Need to indicate the size of the end

3. The memory size in which the packet is defined needs to be formatted with a struct module

Python Socket TFTP protocol

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.