当前位置:网站首页>Simple file transfer protocol TFTP
Simple file transfer protocol TFTP
2022-06-28 02:58:00 【ZhuMou】
One . Introduction to simple file transfer protocol
File transfer protocol (FTP) regulates the way to access files locally from remote servers .
File transfer protocols fall into two categories :1.online-access and 2.whole file copying. The representative agreement of the former is NFS, Similar to sharing documents , Changes to the file locally will affect the file on the server . The latter is essentially a reproduction : Upload files to the server ( Put the local file copy To the server ) And downloading files from the server ( The file copy To local ). Modification of a copy , Will not affect the original file .
TFTP The full name is Trivial File Transfer Protocol, And FTP In comparison, it is simple :
1. be based on UDP Designed application layer protocol . Port is 69. Of course, other transport layer protocols are also supported , such as TCP.
2. No, access control, That is, there is no login verification .
3. There are no folders , All the files are in the root directory .
4. The concept of design is simple, simple and simple , So the cost is very small , It is commonly used in diskless workstations and has strict memory requirements ( Small available memory ) Environment .
Two .TFTP packet format

TFTP packet from TFTP header and TFTP data form . There is a two byte opcode Marked with the TFTP packet The type of , All in all 5 Kind of . We will introduce them one by one .
2.1 RRQ(read request)

opcode = 01( In the decimal sense ), Indicates that the packet by RRQ type , It is used to locally apply to the server for downloading files . The file name is from filename Field assignment , by ASCII Code string , Variable length , With NULL ending .mode The field is also a variable length ASCII Code string , With NULL ending , It defines the file transfer mode ( Transfer mode of files in different formats , Or the way must be different , Such as binary files and txt file ), We'll talk about later .
2.2 WRQ(write request)

It is used to apply for uploading files to the server locally ,opcode by 02. The rest and RRQ Agreement .
2.3 DATA(data)

opcode = 03. Used for data transmission when uploading or downloading files . File is too large. , Will be split into multiple data segments for transmission .block# The field identifies the sequence number of the data segment , Facilitate the reorganization of subsequent data .data Field placement 0-512 Bytes of data . For sizes other than 512 Byte multiples of the file , the last one data packet Of data The size of the field is less than 512 byte ; For exactly 512 Byte multiple size file , In the end, they often send a message data field by 0 Bytes of data packet, To avoid a data field by 512 Byte size data packet As the last of the file data packet.
2.4 ACK(acknowledgement)

opcode = 04. Used by the server for local transport data packet Response . For example, there is a local block# by xxx Of data packet, The server will confirm after receiving it , Return to one block# The field is also xxx Of data packet.
Attention is only to data packet The confirmation of , Yes WRQ and RRQ And other types will not return ACK.
2.5 ERROR(error)

opcode = 05.errcode Field indicates the error type ,errorstring Field gives an error message . among errorstring In order to ASCII Error prompt in the form of code string , Its variable length , And in NULL ending .
2.6 transfer mode explain
Introduction to transmission txt Of documents Netascii And transfer binary files Octet Pattern .
Netascii Mode is used to transmit txt File format , It is transmitted by line . The sender will add... At the end of each line \r\n, And the receiver will remove it .
Octet For binary file transfer , Is transmitted in bytes , The sender and the receiver do not need to do similar addition and removal processing .
3.TFTP Agreement that
TFTP Agreed packet format Stated , The following instructions TFTP Of operations.
We know TFTP Is a simple file transfer for point-to-point , These two points are actually symmetrical , Can be used as a server or a client .TFTP Is based on UDP The design of the , This is very strange , In particular, it is necessary to ensure the reliability of file transmission , and UDP Reliability is not guaranteed . So who guarantees the reliability of file transfer ? Nature is the application layer TFTP agreement , Its use ACK type packet Guarantee data packet Reliability of transmission .
3.1 TFTP The basic process of transferring documents and the guarantee of reliability
We only consider the process of data transmission ( Just consider ACK and DATA packet), Not for now WRQ and RRQ etc. packet.
Remember two facts :
1. First ,server and client Each end maintains a timer , It is used to judge whether the data it sends has timed out .
2. in addition ,server and client The end transmission data adopts stop and wait The way , No confirmation of the last data was received , Don't send the next one .
Server End send data[1], And start timing , can do with client End ack(1) Response . If timer timeout Still not received after ack(1), be server It is believed that data[1] The loss of , And retransmit ; Once received within the time limit ack(1),server Will be sent immediately ack(2).
Client Termination received data(1), Send it now ack(1), And start timing , Hope to receive server End data(2) Response . If timer timeout Still not received after data(2), be client It is believed that ack(1) The loss of , And retransmit ; Once received within the time limit data(2),client The client will immediately send ack(2).
3.2 SAS(sorcerer's apprentice syndrome)
This represents the original TFTP Defects in the agreement . The original TFTP Protocol design :client Once the end receives ack(n), Whether received or not , All sent immediately data(n+1), Even if data(n+1) Already sent ;server Once the end is data(n), Whether received or not , All sent immediately ack(n). and dealyed but not lost ack May trigger SAS, Make the following data Are transmitted twice .

The solution is in sender Add a judgment to the end algorithm , if ack(n) repeat , No data will be sent data(n+1).
3.3 State transition diagram
Five kinds packet There is no end of transmission in , Need to rely on DATA packet Implicitly represent (data Insufficient domains 512B).


for fear of SAS, You can put server Terminal ACK(n) Change it to :ACK(n) and not duplicate.
3.4 Message sequence diagram

边栏推荐
- Usage differences between isempty and isblank
- [2D code image correction and enhancement] simulation of 2D code image correction and enhancement processing based on MATLAB
- 【方块编码】基于matlab的图像方块编码仿真
- 数仓的字符截取三胞胎:substrb、substr、substring
- [plug in -statistical] statistics the number of code lines and related data
- Arduino esp8266 web LED control
- 【模糊神经网络】基于matlab的模糊神经网络仿真
- 分布式事务—基于消息补偿的最终一致性方案(本地消息表、消息队列)
- [today in history] June 16: Oracle Bone Inscriptions was established; Microsoft MSX was born; The inventor of fast Fourier transform was born
- Mixed programming of C language and assembly language in stm32
猜你喜欢

What if win11 cannot use dynamic wallpaper? Solution of win11 without dynamic wallpaper

CMU提出NLP新范式—重构预训练,高考英语交出134高分

Le routage des microservices de la passerelle a échoué au chargement des ressources statiques des microservices

在线文本按行批量反转工具

Win11新建不了文本文档?Win11右键无法新建文本文档的解决方法
![[today in history] June 16: Oracle Bone Inscriptions was established; Microsoft MSX was born; The inventor of fast Fourier transform was born](/img/4f/67e1598b523058a8fb6f3148136902.png)
[today in history] June 16: Oracle Bone Inscriptions was established; Microsoft MSX was born; The inventor of fast Fourier transform was born

JDBC与MySQL数据库

JDBC and MySQL databases

Why are so many people keen on big factories because of the great pressure and competition?
![[today in history] June 25: the father of notebook was born; Windows 98 release; First commercial use of generic product code](/img/ef/a26127284fe57ac049a4313d89cf97.png)
[today in history] June 25: the father of notebook was born; Windows 98 release; First commercial use of generic product code
随机推荐
毕业季来临,2022届高校毕业生人数首次突破千万大关
[kotlin] basic introduction and understanding of its syntax in Android official documents
Intel Ruixuan A380 graphics card will be launched in China
横向滚动的RecycleView一屏显示五个半,低于五个平均分布
微信小程序中生成二维码
How to systematically learn LabVIEW?
[today in history] June 3: Microsoft launched Bing search engine; Larry Roberts starts ARPANET; The father of Visual Basic was born
ByteDance Interviewer: how to calculate the memory size occupied by a picture
A low-cost method to increase private domain traffic with simple maintenance
第三批入围企业公示!年度TOP100智能网联供应商评选
[fuzzy neural network] simulation of fuzzy neural network based on MATLAB
树莓派-环境设置和交叉编译
Gateway微服务路由使微服务静态资源加载失败
Is it safe for qiniu to open an account? How do I open an account online?
在线JSON转PlainText工具
ADB double click the power key command
在线文本按行批量反转工具
Moving Tencent to the cloud: half of the evolution history of cloud server CVM
为什么大厂压力大,竞争大,还有这么多人热衷于大厂呢?
"Dadao Zhichuang" won a ten million prea+ round of financing and launched a technology consumption robot