Transfer files over TCP
- Send file or folder
- resume from break-point
- update existing copy
- GUI
A folder is treated as multiple files in it.
To start, client sends the file header including structure as follows:
| name_size | name | md5 | compress | data_size |
|---|---|---|---|---|
| 4 bytes | [name_size] bytes | 16 bytes | 1 byte | 8 bytes |
name_sizeindicates the length of the name that follows.nameis the UTF-8 encoded file name, with its relative path if sent in folder, it uses the same unix seperator in header and is connverted before sending and after receiving.md5is the calculated MD5 of the original file.compressindicates weather the followingdatais compressed or not.data_sizeis the size ofdata(compressed size ifcompress)
On server side, it first read name_size, if 0 then the transfer process is over, else it reads all the header then sends shift back to client, which tells client the starting position of file and determines the length of data that follows.
Here's how shift is determined:
- if
[name].downloadexits andmd5==[name].md5, thenshift=[name].download - if
[name]exits and its md5 is identical, thenshift=0xffffffffffffffff - else
shift=0
Once client receives shift, it will send data starting from shift.
Python 3 is required.
Tested on both Linux and Windows.