MTC Sync Script
A bash automation tool for synchronizing project files from a remote server to your local machine with automatic VS Code SFTP configuration.
Overview
MTC Sync Script streamlines the process of downloading and setting up projects from remote servers. It automates:
- Creating compressed archives on the remote server
- Downloading files via SCP
- Extracting and organizing files locally
- Configuring VS Code for SFTP development
Perfect for developers working with remote projects who want a fast, one-command setup experience.
Features
- ✅ Interactive Setup - Simple prompts for server and local paths
- ✅ Automated Sync - Compress, download, and extract in one command
- ✅ VS Code Integration - Auto-generates SFTP configuration
- ✅ Error Checking - Validates each step with helpful error messages
- ✅ Cleanup - Removes temporary files automatically
- ✅ Colored Output - Clear status messages with color coding
Requirements
System Dependencies
- Bash shell
- SSH/SCP - Secure shell commands (usually pre-installed on macOS/Linux)
- sshpass - Password-based SSH authentication tool
- tar - Archive/compression utility (pre-installed)
Installation of Dependencies
macOS (using Homebrew):
brew install sshpass
Ubuntu/Debian:
sudo apt-get install sshpass openssh-client
CentOS/RHEL:
sudo yum install sshpass openssh-clients
Server Requirements
- SSH access to the remote server
- Project files in a known folder path (e.g.,
~/public_leo)
Usage
Basic Usage
-
Make the script executable (if needed):
chmod +x sync-project.sh -
Run the script:
./sync-project.sh -
Answer the prompts:
- Server address: Enter your server credentials (e.g.,
user@server.comorleo@192.168.1.100) - Server project path: Path where your project is stored on the server (e.g.,
~/public_leo) - Local folder: Where you want to download the project (e.g.,
./my_project) - SSH password: Your password when prompted
- Server address: Enter your server credentials (e.g.,
Example Session
$ ./sync-project.sh
Enter server address (user@host): leo@myserver.com
Enter server project path: ~/public_leo
Enter local folder path: ./my_project
[System will prompt for SSH password]
✓ Archive created successfully
✓ File transfer complete
✓ Extraction complete
✓ VS Code SFTP config created
What the Script Does
- Connects to Remote Server - Uses SSH to authenticate with password or key
- Creates Archive - Compresses project files into
tar.gzformat on server - Downloads Archive - Uses SCP to securely copy archive to local machine
- Extracts Files - Unpacks the archive to your specified local folder
- Cleans Up - Removes temporary archive files
- Configures VS Code - Creates
.vscode/sftp.jsonfor seamless SFTP workflow
VS Code SFTP Configuration
The script automatically generates a .vscode/sftp.json file with:
- Auto-upload on save - Changes sync to server immediately
- Pre-configured ignore patterns - Excludes common folders:
node_modules/vendor/storage/.vscode/.git/- And others...
This allows you to continue developing locally and have changes automatically uploaded to the remote server.
Error Handling
The script includes error checking at each step:
- ✓ Validates SSH connection
- ✓ Checks if remote path exists
- ✓ Verifies archive creation
- ✓ Confirms successful download and extraction
- ✓ Exits gracefully with error messages if anything fails
Troubleshooting
"sshpass: command not found"
Install sshpass using the commands above for your OS.
"SSH connection refused"
- Verify server address is correct
- Check that SSH is enabled on the server
- Confirm your username and password
"Remote path not found"
- Verify the server project path is correct
- Ensure the path exists on the server
- Check user permissions
"Local folder already exists"
The script will still sync, but existing files will be overwritten. Back up important files first.
License
This script is provided as-is for development and synchronization purposes.
Contributing
Feel free to improve this script or report issues!