A robust client-server file backup and retrieval system implementing a stateless protocol over TCP/IP. The system consists of a C++ server component and a Python client that communicate via a custom binary protocol.
- Language: C++17
- Architecture: Stateless, thread-based concurrency
- Dependencies: Boost 1.88.0 (ASIO for networking)
- Design Pattern: Object-oriented with RAII principles
- Language: Python 3.9+
- Architecture: Object-oriented design
- Dependencies: Standard libraries only (socket, struct)
All data is transmitted in little-endian format with unsigned numeric values.
| Field | Size | Description |
|---|---|---|
| user_id | 4 bytes | Client unique identifier |
| version | 1 byte | Protocol version |
| op | 1 byte | Operation code |
| name_len | 2 bytes | Length of filename |
| filename | Variable | ASCII filename |
| size | 4 bytes | Size of payload |
| payload | Variable | Binary file content |
| Code | Operation | Description | Fields Used |
|---|---|---|---|
| 100 | FILE_BACKUP | Store file on server | All fields |
| 200 | FILE_RESTORE | Retrieve file from server | All except size and payload |
| 201 | FILE_REMOVE | Delete file from server | All except size and payload |
| 202 | FILE_DIR | List client's files | Only user_id, version, op |
| Field | Size | Description |
|---|---|---|
| version | 1 byte | Server version |
| status | 2 bytes | Status code |
| name_len | 2 bytes | Length of filename |
| filename | Variable | ASCII filename |
| size | 4 bytes | Size of payload |
| payload | Variable | Binary file content |
| Code | Status | Description | Fields Used |
|---|---|---|---|
| 210 | SUCCESS_RESTORE | File successfully restored | All fields |
| 211 | SUCCESS_DIR | File list successfully returned | All fields |
| 212 | SUCCESS_BACKUP_DELETE | File backed up or deleted successfully | All except size and payload |
| 1001 | ERROR_NOT_EXIST | File does not exist | All except size and payload |
| 1002 | ERROR_NO_FILES | Client has no files | Only version and status |
| 1003 | ERROR_GENERIC | Generic server error | Only version and status |
c:\backupsvr\[CLIENT_ID]\[FILENAME]
- Thread-safe user handling with atomic locks
- Efficient memory management with RAII principles
- Secure random string generation
- Robust error handling
- Support for large file transfers
- server.info: Contains server IP and port in format
IP:PORT - backup.info: Contains list of files to backup (one per line)
- Unique client ID generation
- Automatic file operations sequence
- Robust error handling
- Type-safe implementation
- Visual Studio 2019 or newer
- Boost Library 1.88.0
- Windows 10 or newer
- Download Boost 1.88.0 from boost.org
- Extract to a location of your choice (e.g.,
C:\boost_1_88_0) - Open Visual Studio Developer Command Prompt
- Navigate to the Boost directory:
cd C:\boost_1_88_0 - Build Boost libraries:
bootstrap.bat b2 --toolset=msvc-14.2 address-model=64 --build-type=complete
-
Open the solution in Visual Studio
-
Right-click on the project and select Properties
-
Configure the following settings:
C/C++ → General → Additional Include Directories:
C:\boost_1_88_0Linker → General → Additional Library Directories:
C:\boost_1_88_0\stage\libC/C++ → Preprocessor → Preprocessor Definitions:
WIN32_WINNT=0x0A00C/C++ → Language → C++ Language Standard:
C++17 (/std:c++17) -
Disable Precompiled Headers:
- Navigate to C/C++ → Precompiled Headers
- Set "Precompiled Header" to "Not Using Precompiled Headers"
- Build the solution in Visual Studio (Release configuration recommended for production)
- The executable will be generated in the output directory
- Python 3.9 or newer
- Place the client files in a directory
- Create or update
server.infowith the server's IP and port:127.0.0.1:1234 - Create or update
backup.infowith the files to backup:file1.txt file2.pdf - Ensure the files listed in
backup.infoexist in the same directory
- Run the server executable:
BackupServer.exe - The server will start listening for connections on the default port (1234)
- Open a command prompt in the client directory
- Run the client script:
python client.py - The client will automatically execute the required sequence of operations:
- Request file list
- Backup two files
- Request updated file list
- Restore a file to 'tmp'
- Delete a file
- Attempt to restore the deleted file
- Input validation on both client and server
- Memory safety with RAII and smart pointers
- Secure random number generation
- Proper error handling and logging
- Protection against buffer overflows
- Network errors are gracefully handled
- File system errors are properly reported
- Invalid requests are rejected with appropriate status codes
- Resource cleanup is guaranteed even in error conditions
- All numeric fields use little-endian byte ordering
- The protocol is binary for efficiency
- The server is designed to be stateless
- Thread safety is maintained for concurrent client connections
- Large file transfers are handled efficiently with chunking
- Memory usage is optimized with appropriate buffer sizes
- File operations use efficient streaming
- Network operations are non-blocking where appropriate
- Thread pool management for concurrent connections
Natanel Fishman - Defensive Programming Course, 2025
This project is for educational purposes only.
