Skip to content

Client-Server file backup system over TCP using a custom binary protocol (CPP server, Python client).

Notifications You must be signed in to change notification settings

Natifishman/FileBackupSystem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

App Showcase

Overview

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.

Components

Server (C++)

  • Language: C++17
  • Architecture: Stateless, thread-based concurrency
  • Dependencies: Boost 1.88.0 (ASIO for networking)
  • Design Pattern: Object-oriented with RAII principles

Client (Python)

  • Language: Python 3.9+
  • Architecture: Object-oriented design
  • Dependencies: Standard libraries only (socket, struct)

Protocol Specification

Binary Format

All data is transmitted in little-endian format with unsigned numeric values.

Request Structure

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

Request Operation Codes

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

Response Structure

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

Response Status Codes

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

Server Implementation Details

File Storage Structure

c:\backupsvr\[CLIENT_ID]\[FILENAME]

Features

  • 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

Client Implementation Details

Configuration Files

  • server.info: Contains server IP and port in format IP:PORT
  • backup.info: Contains list of files to backup (one per line)

Features

  • Unique client ID generation
  • Automatic file operations sequence
  • Robust error handling
  • Type-safe implementation

Installation and Setup

Server (C++)

Prerequisites

  • Visual Studio 2019 or newer
  • Boost Library 1.88.0
  • Windows 10 or newer

Boost Setup

  1. Download Boost 1.88.0 from boost.org
  2. Extract to a location of your choice (e.g., C:\boost_1_88_0)
  3. Open Visual Studio Developer Command Prompt
  4. Navigate to the Boost directory:
    cd C:\boost_1_88_0
    
  5. Build Boost libraries:
    bootstrap.bat
    b2 --toolset=msvc-14.2 address-model=64 --build-type=complete
    

Project Configuration

  1. Open the solution in Visual Studio

  2. Right-click on the project and select Properties

  3. Configure the following settings:

    C/C++ → General → Additional Include Directories:

    C:\boost_1_88_0
    

    Linker → General → Additional Library Directories:

    C:\boost_1_88_0\stage\lib
    

    C/C++ → Preprocessor → Preprocessor Definitions:

    WIN32_WINNT=0x0A00
    

    C/C++ → Language → C++ Language Standard:

    C++17 (/std:c++17)
    
  4. Disable Precompiled Headers:

    • Navigate to C/C++ → Precompiled Headers
    • Set "Precompiled Header" to "Not Using Precompiled Headers"

Building the Server

  1. Build the solution in Visual Studio (Release configuration recommended for production)
  2. The executable will be generated in the output directory

Client (Python)

Prerequisites

  • Python 3.9 or newer

Setup

  1. Place the client files in a directory
  2. Create or update server.info with the server's IP and port:
    127.0.0.1:1234
    
  3. Create or update backup.info with the files to backup:
    file1.txt
    file2.pdf
    
  4. Ensure the files listed in backup.info exist in the same directory

Running the System

Starting the Server

  1. Run the server executable:
    BackupServer.exe
    
  2. The server will start listening for connections on the default port (1234)

Running the Client

  1. Open a command prompt in the client directory
  2. Run the client script:
    python client.py
    
  3. 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

Security Considerations

  • 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

Error Handling

  • 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

Development Notes

  • 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

Performance Considerations

  • 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

Author

Natanel Fishman - Defensive Programming Course, 2025

License

This project is for educational purposes only.

About

Client-Server file backup system over TCP using a custom binary protocol (CPP server, Python client).

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published