---
# System prepended metadata

title: '[ ZPR - Project ] Final documentation'

---

# [ ZPR - Project ] Final documentation

***This is the final documentation of the project on the subject of*** **ZPR 22Z.**

#### The project was done by:
```
Minh Nguyen Cong - 317077
Andrii Demydenko - 317084
```
*All information about: how to run code, build documentation, build code etc. You can find in a README.md*
w
## 1. Topic of the project
**Topic**: Tool for synchronizing the contents of directories through a server accessible via ssh.

Project outcome is to create an application that perform continuous data synchronization of a specified folder between a local PC and a remote Server and implement the following requirements:
* server access via ssh
* main functionality should correspond to the **Unison** functionality

## 2. Tasks 
Based on the topic of the project, our **Main tasks** were: 
* establish a connection via SSH 
    * connection with SSH key
    * connection with a password
* run bash commands on a host and get a response
* detect changed files
    * compare the last local and remote file modification dates
    * create a file structure (tree) for the possibility of easily detecting changes
* one-time folder synchronization

**Secondary tasks:** 
* possibility to choose which files should be synchronized
* update only changed part of the file

Our program works on such operating systems as: Linux, MacOS, ~~Windows~~.


### 3. What has been achieved
The project has successfully achieved the majority of its objectives. The application, when executed with the necessary parameters, is capable of synchronizing directories with ease. Furthermore, the user has the flexibility to select which files should be synced. The only outstanding task is the implementation of partial file updates, as the current version of the program replaces the entire file.

### 4. Main classes of the project

The ```Logging``` class offers a comprehensive logging system for the program, with the ability to access logs at four different levels.

The ```SyncSession``` class is responsible for comparing the contents of the working directories of a local machine and a host machine, and synchronizing them by copying new or updated files and directories from one machine to the other.

The project contains these following classes:
```
class Connection
class Directory
class File
class Machine
class HostMachine: public Machine
class LocalMachine: public Machine
```


### 5. Code analysis

[![Coverage Status](https://coveralls.io/repos/github/PW-mates/zpr-project/badge.svg?branch=main)](https://coveralls.io/github/PW-mates/zpr-project?branch=main)

![Build status](https://github.com/PW-mates/zpr-project/actions/workflows/c-cpp.yml/badge.svg?branch=main)

**Number of lines of code**

| .cc/.h | number of files | number of lines |
| -------- | -------- | -------- |
| .cc     | 13     | 1120     |
| .h      |   9       |     240     |


### 6. Summary of how program work
First of all our program work using SSH protocol. In this regard, the first that program does is establish SSH connection using SSH key path or password (user can choose a method as a parameter). 

The next step is to determine what needs to be synchronized. To do it program runs a bash script that shows the data of the folder we are interested in such as dates of the last modifications, file sizes, etc. Using this data program builds a file catalog (something like a tree), comparing local and remote tree program decide which files should be actualized.

The process of file synchronization is carried out using SFTP protocol. The program simply asks which files should be updated.  You can press ```y``` to update the currently displayed file or press ```Y``` to apply ```y``` for all files further down the list.
### 7. Summary
The implementation of our project was a smooth process, thanks to the thoughtful selection of libraries we utilized. The libSSH library in particular, greatly simplified the task of working with SSH in C++.
What can be improved:
* add more UI 
* add possibility to run program with configuration file
* update only the changed part of the file
* add support for Windows