A file backup program that transfers files from client side to server side sandbox using socket in C. After the file transfer is done, it automatically checks the integrity of the file by calculating a new hash value and comparing it with the one that server has received. If they match, the process is completed. Otherwise, client will be asked to resend that file.
Just like the local version, multiple processes are used to transfer files concurrently, which speeds up the program.
pid_t pid = fork(); // Handle recursive calls for each subdirectory.
- Terminal/Console (in UNIX) OR PowerShell (in Windows)
Download source code and compile
The following instructions are presented using Terminal in macOS:
# Change to HOME directory $ cd ~ # Clone this repo and 'cd' into it $ git clone https://github.com/jellycsc/file-sync-over-socket.git $ cd file-sync-over-socket/ # Let's compile both client and server # Note: You can change the port number in the Makefile. $ make gcc -DPORT=18229 -g -Wall -std=gnu99 -c rcopy_client.c gcc -DPORT=18229 -g -Wall -std=gnu99 -c ftree.c gcc -DPORT=18229 -g -Wall -std=gnu99 -c hash_functions.c gcc -DPORT=18229 -g -Wall -std=gnu99 -o rcopy_client rcopy_client.o ftree.o hash_functions.o gcc -DPORT=18229 -g -Wall -std=gnu99 -c rcopy_server.c gcc -DPORT=18229 -g -Wall -std=gnu99 -o rcopy_server rcopy_server.o ftree.o hash_functions.o
Usage: rcopy_client SRC HOST SRC - The file or directory to copy to the server HOST - The hostname of the server
Usage: rcopy_server PATH_PREFIX PATH_PREFIX - The path on the server used as the path prefix for the destination
# Let's start by transferring a sample Java project folder $ ./rcopy_client workspace1/ localhost Socket connection established. Copy completed successfully
$ ./rcopy_server dest/ workspace1 workspace1/final_test workspace1/final_test/src workspace1/final_test/src/final_test File transfer is completed! workspace1/final_test/src/final_test/B.java File transfer is completed! workspace1/final_test/src/final_test/Super.java File transfer is completed! workspace1/final_test/src/final_test/in.java File transfer is completed! workspace1/final_test/src/final_test/Child1.java File transfer is completed! workspace1/final_test/src/final_test/Test.java File transfer is completed! workspace1/final_test/src/final_test/Child11.java File transfer is completed! workspace1/final_test/src/final_test/Test1.java File transfer is completed! workspace1/final_test/src/final_test/A.java workspace1/final_test/src/haha File transfer is completed! workspace1/final_test/src/haha/Test.java CLIENT  HAS DISCONNECTED.
All client files have been successfully backed up to
sandbox folder on the server, which has permission
0400. Having said that, this prevents clients from trying to create files and directories above the dest directory.
|Chenjie (Jack) Nifirstname.lastname@example.org|
|Jialiang (Jerry) Yi||JerryGoremail@example.com|
Thoughts and future improvements
- Processes can be replaced with threads. The later ones are more light-weighted with less overheads.
Contributing to this project
- Fork it
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -m 'Add some feature')
- Push to your feature branch (
git push origin my-new-feature)
- Create a new Pull Request
Details are described here.
issue button above↑ to report any issues related to this project
OR you can shoot an email to firstname.lastname@example.org
This project is licensed under GNU General Public License v3.0 - see LICENSE file for more details.