Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

🚀 Git FTP Sync

Python 3.6+ AI-Assisted License: MIT

Upload only the files that have changed in your Git repository to an FTP server.
No more uploading entire projects – just the differences. Remote directories are created automatically.


✨ Features

  • 🔍 Smart file detection – Uses git status to find modified, staged, and untracked files.
  • 📁 Auto‑directory creation – Missing remote folders are created on the fly.
  • 🗑️ Remote deletion – Deletes files on the server that were removed locally (optional).
  • 🛡️ Dry‑run mode – See what would happen without touching your FTP server.
  • Skip confirmation – For CI/CD or scripting (--yes).
  • 🔐 Credentials safety – Config file is separate, add it to .gitignore to prevent leaks.

📦 Requirements

  • Python 3.6 or newer
  • Git (must be installed and accessible in your PATH)

🛠️ Setup

1. Clone the repository

git clone https://github.com/rafiz001/git_ftp_sync.git
cd git_ftp_sync

2. Create ftp_config.json

Create a file named ftp_config.json next to the script (or pass a custom path with --config).

{
  "host": "ftp.example.com",
  "port": 21,
  "user": "myuser",
  "password": "mypassword",
  "remote_base": "/public_html",
  "use_tls": false
}
Field Description
host FTP server hostname or IP address
port FTP port (default: 21)
user FTP username
password FTP password
remote_base Remote root path where files will be uploaded (e.g. /public_html)
use_tls Set to true to use FTP over TLS (FTPS)

3. Protect your credentials

Add ftp_config.json to your .gitignore to prevent accidental commits:

echo "ftp_config.json" >> .gitignore

🧪 Usage

Run the script from inside your Git repository (the script automatically detects the repo root).

python git_ftp_sync.py

By default, it will:

  • Show a summary of files to upload / delete.
  • Ask for confirmation before proceeding.

Command-line options

Option Description
--config FILE Use an alternative config file (default: ftp_config.json)
--dry-run Print what would be uploaded/deleted without making any FTP changes
--no-delete Upload only; do not delete files on the server even if removed locally
--yes, -y Skip the confirmation prompt (useful for automated scripts)

Examples

# Preview changes without uploading
python git_ftp_sync.py --dry-run

# Upload immediately without asking
python git_ftp_sync.py --yes

# Only upload new/modified files, never delete anything
python git_ftp_sync.py --no-delete

# Use a different config file
python git_ftp_sync.py --config /path/to/ftp_config.json

🔧 How It Works

  1. The script runs git status --porcelain=v1 --untracked-files=all to get a list of changed files.
  2. It distinguishes between modified (including new/untracked) and deleted files.
  3. For each modified file, it uploads it to the remote path: remote_base + local_path.
  4. If deletion is enabled, it removes files on the server that are deleted locally.
  5. Missing remote directories are created recursively before each upload.

⚠️ Troubleshooting

Problem Solution
git not found Install Git and ensure it's in your PATH.
Not inside a git repository Run the script from within a Git repository.
Config file not found Create ftp_config.json or provide the path with --config.
FTP connection errors (timeout, auth) Verify your FTP credentials and network connectivity.
550 errors when creating directories The directory may already exist; these are ignored and the upload continues.
Files are not being detected Check if .gitignore excludes them. The script only sees files tracked by Git.

🤖 Acknowledgments

This project was created with the assistance of Claude AI (Anthropic).
Claude helped design the architecture, write the code.


📄 License

This project is open‑source and available under the MIT License.


📬 Feedback & Contributions

Feel free to open an issue or pull request on GitHub.
All contributions are welcome!


Happy syncing! 🚀

About

Upload only the files that have changed in your Git repository to an FTP server.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages