watch-sync

module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 19, 2025 License: MIT

README

Watch-Sync

A Go console application that watches directories for changes and synchronizes them using various protocols (FTP, SFTP, Rsync).

Go Report Card Go Version

Features

  • File System Watching: Monitors a directory for file/folder creation, modification, and deletion
  • Recursive Watching: Detects changes in subdirectories
  • Multiple Sync Methods:
    • FTP upload
    • SFTP upload
    • Rsync synchronization (preserves directory structure)
  • Configurable: Uses JSON configuration file stored in the user's home directory
  • Graceful Shutdown: Properly cleans up resources on exit
  • Ignores CHMOD Events: Avoids unnecessary syncs for permission changes

Installation

Using Go
# Clone the repository
git clone https://github.com/erkineren/watch-sync.git
cd watch-sync

# Build and install
make install
From Binary

Download the latest binary from the releases page.

Usage

# Watch the current directory with no actions
watch-sync

# Watch a specific directory
watch-sync -path /path/to/watch

# Watch with specific actions to trigger
watch-sync -actions prod-ftp,staging-sftp

# Watch a specific path with specific actions
watch-sync -path /path/to/watch -actions backup-rsync

# Watch without recursion (top level only)
watch-sync -recursive=false -actions prod-ftp

# Enable verbose logging
watch-sync -verbose -actions backup-rsync

Configuration

The configuration file is stored at ~/.watch-sync.json. If it doesn't exist, a default one will be created.

Example configuration:

{
  "actions": {
    "prod-ftp": {
      "type": "ftp",
      "settings": {
        "host": "ftp.example.com",
        "port": 21,
        "user": "username",
        "password": "password",
        "remote_dir": "/public_html"
      }
    },
    "staging-sftp": {
      "type": "sftp",
      "settings": {
        "host": "sftp.example.com",
        "port": 22,
        "user": "username",
        "password": "password",
        "key_file": "/path/to/private_key",
        "remote_dir": "/var/www"
      }
    },
    "backup-rsync": {
      "type": "rsync",
      "settings": {
        "host": "example.com",
        "user": "username",
        "remote_dir": "/var/www/html",
        "options": "-av --delete"
      }
    }
  },
  "filters": {
    "exclude": [".git", "node_modules", "*.tmp", "vendor", "*.log"]
  }
}

With this configuration, you can reference your actions by name when running the command:

watch-sync -actions prod-ftp,staging-sftp

Recent Improvements

  • Fixed rsync path preservation: rsync now correctly preserves directory structure on the remote server
  • Ignore CHMOD events: CHMOD events no longer trigger synchronization actions
  • Better error handling: Improved error logging and recovery

Contributing

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

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Dependencies

  • fsnotify - Cross-platform file system notifications
  • sftp - SFTP client for Go
  • ftp - FTP client for Go

Directories

Path Synopsis
cmd
watch-sync command
Package main provides the entry point for the watch-sync application.
Package main provides the entry point for the watch-sync application.
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL