A Go console application that watches directories for changes and synchronizes them using various protocols (FTP, SFTP, Rsync).
- 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
# Clone the repository
git clone https://github.com/erkineren/watch-sync.git
cd watch-sync
# Build and install
make install
Download the latest binary from the releases page.
# 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
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
- 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
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.