Skip to content

Zhao-Michael/gorsync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gorsync

A cross-platform file synchronization command-line tool similar to rsync, designed for local network use with TCP-based transfer.

Important Security Note: This tool is strongly recommended for use within local networks only, preferably through network grouping (e.g., VPN or LAN). Do not use it directly over the public internet as it does not include encryption or authentication mechanisms.

Project Origin

This project was generated by TraeAI

Features

  • Cross-platform compatibility: Works on Windows, macOS, and Linux
  • TCP-based network transfer: For reliable file synchronization within local networks
  • File integrity verification: Uses MD5 hash calculation to ensure file integrity
  • Progress printing: Detailed transfer progress information during file synchronization
  • Safe file operations: Uses temporary files with MD5 verification before overwriting target files
  • Sequential file transfer: Processes files one by one for reliable synchronization
  • Simplified sync logic: Directly compares files by MD5 hash for efficient synchronization
  • Automatic cleanup: Removes local files that don't exist on the remote server

Installation

Prerequisites

  • Go 1.16 or later

Build from source

git clone https://github.com/Zhao-Michael/gorsync.git

// build library for windows:

go build -buildmode=c-shared -ldflags="-s -w" -o gorsync.dll ./cmd/gorsync/main.go

// build library for linux:

go build -ldflags "-s -w" -buildmode=c-shared -o gorsync.so ./cmd/gorsync/main.go

// build executable for windows:

go build -o gorsync.exe -ldflags="-s -w" ./cmd/gorsync/main.go

// build executable for linux:

go build -o gorsync -ldflags="-s -w" ./cmd/gorsync/main.go

Use Library

// Start Server
extern int StartServer(void);

// Sync Files
extern int SyncFiles(char* localPath, char* remotePath);

// Stop Server
extern int StopServer(void);

Usage

Start a server (listening mode)

# Start server with default port 8730
gorsync

# Start server with custom port
gorsync -listen 9000

Sync files (client mode)

# Sync from remote source to local destination (default port 8730)
gorsync -path /path/to/destination -remote 192.168.1.100:/path/to/source

# Sync with custom port
gorsync -path /path/to/destination -remote 192.168.1.100:9000:/path/to/source

Command-line Arguments

Argument Description Default
-path Local directory path for synchronization N/A
-remote Remote address in format host[:port]:path (e.g., 192.168.1.100:8730:/src or 192.168.1.100:/src) N/A
-listen Start in listening mode with optional port number 8730

Examples

Basic synchronization

# Server side (listening mode)
gorsync

# Client side (sync operation)
gorsync -path ./destination -remote 192.168.1.100:/source

Using custom port

# Server side (custom port)
gorsync -listen 9000

# Client side (connect to custom port)
gorsync -path ./destination -remote 192.168.1.100:9000:/source

Technical Implementation

Core Components

  • pkg/transfer/transfer.go: File transfer functionality with MD5 verification
  • pkg/net/server.go: TCP server for file transfer
  • pkg/net/client.go: TCP client for file transfer
  • pkg/sync/sync.go: Synchronization logic
  • pkg/diff/diff.go: File difference comparison
  • pkg/utils/hash.go: MD5 hash calculation utilities

Key Features

  1. File Transfer: Uses TCP for reliable file transfer with MD5 verification to ensure file integrity
  2. Sequential Transfer: Processes files one by one for reliable synchronization
  3. Safe Operations: Uses temporary files and safe rename operations to ensure atomic file updates
  4. Progress Tracking: Provides detailed progress information during file transfer
  5. Simplified Sync Logic: Directly compares files by MD5 hash for efficient synchronization
  6. Automatic Cleanup: Removes local files that don't exist on the remote server

Network Protocol

  • Uses TCP for all file transfers
  • Default port: 8730
  • Supports binary file transfer with chunked encoding
  • Includes MD5 hash verification for file integrity

Project Structure

gorsync/
├── cmd/
│   └── gorsync/          # Command-line interface
│       └── main.go       # Main entry point
├── pkg/
│   ├── diff/             # File difference comparison
│   ├── net/              # Network client/server implementation
│   ├── sync/             # Synchronization logic
│   ├── transfer/         # File transfer functionality
│   └── utils/            # Utility functions
├── go.mod                # Go module definition
└── README.md             # This file

Testing

  1. Start a server in listening mode
  2. Run a client to sync files to the server
  3. Verify that files are correctly synchronized

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Acknowledgements

  • Inspired by gokrazy/rsync but with simplify codes and supoort for windows.
  • Built with Go's standard library and cross-platform compatibility in mind

About

A cross-platform file synchronization command-line tool similar to rsync, designed for local network use with TCP-based transfer.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors