A lightweight FTP sync script for static/web project deployment.
This repository was built as a learning-oriented tool to support my web development study workflow while still being reusable by other developers.
- Upload local files to an FTP server
- Keep local files as source of truth
- Delete remote orphan files (within current script behavior)
- Upload individual files for quick fixes (new in this version)
- VS Code integration with tasks.json (new in this version)
- Ignore paths via
.ftpignore - Externalized configuration via
.env - Configurable workspace paths via environment variables
- Python 3
- Standard library modules only (
ftplib,pathlib,fnmatch,os,sys)
syncftp.py— canonical script entrypoint.env.example— safe configuration template.ftpignore— ignore pattern file exampleLICENSE— BSD-3-Clause license (requires keeping copyright notice)
- Copy the environment template:
cp .env.example .env-
Edit
.envwith your FTP credentials and paths. -
Run one of the commands:
python3 syncftp.py upload
python3 syncftp.py download
python3 syncftp.py syncUploads all local files and removes remote files not present locally (full synchronization).
python3 syncftp.py upload
# or (alias):
python3 syncftp.py syncUse case: Complete deployment or full site synchronization.
Note: Deletes remote orphans—use with caution.
Downloads specific files from the server (configured in .env via DOWNLOAD_FILES).
python3 syncftp.py downloadUploads a single file without removing remote orphans.
python3 syncftp.py upload-file <relative_path> [--strip-prefix <prefix>]Parameters:
<relative_path>— Path to file relative to workspace or with a prefix to strip--strip-prefix <prefix>(optional) — Remove this prefix from the path before uploading
Examples:
# Upload a file in the root
python3 syncftp.py upload-file index.html
# Upload a file in a subdirectory (site-relative)
python3 syncftp.py upload-file restaurante/gestao/painel.php
# Upload with workspace-relative path and strip prefix
python3 syncftp.py upload-file al-page-gd/restaurante/gestao/painel.php --strip-prefix al-page-gd
# Result: uploads as "restaurante/gestao/painel.php" to serverUse case: Quick bug fixes during development. The --strip-prefix option is especially useful when integrating with VS Code tasks that use ${relativeFile} (which may include workspace structure).
sync to ensure full consistency.
Generates VS Code tasks.json configuration for syncftp integration.
python3 syncftp.py setup-vscodeWhat it does:
- Creates/updates
.vscode/tasks.jsonin your workspace - Adds four new tasks for fast FTP operations:
- FTP Upload (syncftp) — full sync with orphan cleanup
- FTP Download (syncftp) — download specified files
- FTP: Upload Current File (syncftp) — upload the file you're currently editing
- FTP: Upload File (with prompt) — upload any file (path pre-filled from current file)
How to use:
- Run
python3 syncftp.py setup-vscodeonce - In VS Code, press
Cmd+Shift+P(macOS) orCtrl+Shift+P(Linux/Windows) - Type "Tasks: Run Task"
- Select your desired FTP task
Quick workflows:
Scenario 1: Upload the file you're editing
- Open
restaurante/gestao/painel.php - Run task "FTP: Upload Current File (syncftp)"
- ✅ Instant upload, no prompts
Scenario 2: Upload a different file
- Run task "FTP: Upload File (with prompt)"
- Prompt appears with current file path pre-filled
- Edit or confirm the path
- ✅ Upload starts
Benefits:
- No need to open terminal for common operations
- Auto-detection of current file for instant uploads
- Pre-filled prompts reduce typing
- Integration directly in VS Code workflow
The script reads configuration from environment variables and from a local .env file.
Required:
FTP_USERFTP_PASS
Common optional values:
FTP_HOST(default:ftpupload.net)FTP_PORT(default:21)FTP_PATH(default:/htdocs)WORKSPACE_DIR(default: parent folder of script)SITE_SUBDIR(default:al-page-gd)WORKSPACE_PREFIX(default: same asSITE_SUBDIR)PASSIVE_MODE(default:true)CONNECTION_TIMEOUT(default:10)UNWANTED_REMOTE_ENTRIES(comma-separated)DOWNLOAD_FILES(comma-separated)
- Never commit
.envwith real credentials. - Rotate FTP credentials immediately if they were ever exposed.
- Keep the repository private while cleaning sensitive history, if needed.
The script supports glob-like matching to exclude files and directories from synchronization.
Examples:
# Ignore documentation files
*.md
*.txt
# Ignore a specific file in a subdirectory
path/to/temporary_file.htmlThis project is designed as a lightweight, reusable tool for developers who need reliable FTP synchronization without complex dependencies. It prioritizes simplicity, transparency, and educational value.
This project was developed with an emphasis on clarity, maintainability, and pragmatic design decisions. The code prioritizes readability and ease of customization for different deployment scenarios.
This project is licensed under the BSD 3-Clause License.
For legal terms, see LICENSE.