Type | Value (Hex) | Description | Direction |
---|---|---|---|
HELLO | 0x01 | Always the first packet of Transferring. | Sender -> Recver |
ACK | 0x02 | An acknowledge of HELLO packet. | Recver -> Sender |
FILE | 0x03 | The FILE packet contains the contents of file. | Sender -> Recver |
END | 0x04 | The last packet contain contents of file. | Sender -> Recver |
GIVEME | 0x05 | Ask packets with certain IDs. | Recver -> Sender |
The HELLO packet is the first packet of transferring for one file.
Name | Length(Byte) | Description |
---|---|---|
Type | 1 | HELLO(0x01) |
Length | 4 | The size of this packet. |
Packet Id | 1 | Packet Id. As same as the one in ACK. |
Blocks | 2 | File Blocks number. (Up to 65535) |
FileName length | 2 | The length of file name. |
FileName | FileName length | File name. |
File CRC | 4 | Checksum of content of file. |
-
Packet Id is random number generated by sender.
-
Actions
Sender MUST drop it If received a HELLO packet.
After decoding the HELLO packet, something followed should be done.
Create a part file for saving. It should be deleted after finishing receive.
Must return a ACK packet with same PacketID to response.
The ACK packet is a acknowledge of HELLO packet.
Name | Length(Byte) | Description |
---|---|---|
Type | 1 | ACK(0x02) |
Length | 4 | The size of this packet. |
Packet Id | 1 | Packet id. As same as the one in HELLO. |
File Id | 4 | File Id. |
- Action
Recver MUST drop it If received a ACK packet.
The FILE packet contains the contents of file. And each block was contained in one Packet. The size of block is define in nftp.h ((256 * 1024) by default).
Name | Length(Byte) | Description |
---|---|---|
Type | 1 | FILE(0x03) |
Length | 4 | The size of this packet. |
File Id | 4 | File Id. As same as the one in ACK. |
Block Seq | 2 | Block sequence number. Start from 0. |
Content length | 4 | The length of content. |
Content | Content length | The content of block. |
- Actions
Sender MUST drop it If received a FILE packet.
Packets from multiple/same files can be transferred at same time.
The END Packet is the last packet contain contents of file. It means the ending of transferring for a file.
Name | Length(Byte) | Description |
---|---|---|
Type | 1 | END(0x04) |
Length | 4 | The size of this packet. |
File Id | 4 | File Id. As same as the one in ACK. |
Block Seq | 2 | Block sequence number. Start from 0. |
Content length | 4 | The length of content. |
Content | Content length | The content of block. |
The GIVEME packet is use to ask a series of packets with certain IDs from Recver.
Name | Length(Byte) | Description |
---|---|---|
Type | 1 | GIVEME(0x05) |
Length | 4 | The size of this packet. |
File Id | 4 | File Id. As same as the one in ACK. |
Blockseq | 2 | The blockseq of the required packet. |
Asking multiple files at once is not supported now :( In the next version of nftp. Ask multiple files will be supported. And the nftp_handler() API may have a change.
Recver MUST drop it If received a GIVEME packet.