Getting started

From nothing to a first synchronization: a site and its server in one command, then a preview.

Every step below works two ways. In a terminal, run sync-servers with no command and use the menus; or type the commands shown, which ask for anything you leave out. In a script, pass every value as an option and nothing is ever asked.

1. Create a site and its server

A site is a name, a local folder (the folder on this computer that holds the files you publish) and the server it is published to. One command sets up all three:

sync-servers site add --name "My Site" --local-root ~/sites/my-site \
  --protocol ftps --host 203.0.113.10 --user demo-user@example.com

On Windows, in cmd.exe:

sync-servers site add --name "My Site" --local-root "C:\Users\<user>\Sites\my-site" ^
  --protocol ftps --host 203.0.113.10 --user demo-user@example.com

Or run sync-servers site add alone and answer the questions:

Site name: My Site
Local site folder [/home/<user>/sites/my-site]:
Protocol
  1. SFTP (recommended)
  2. FTPS, explicit TLS
  3. FTPS, implicit TLS
  4. FTP, insecure: sends the password in clear text
  5. Local or network folder
Choose a number [1]: 2
Host: 203.0.113.10
User: demo-user@example.com
Password:
Connecting to 203.0.113.10:21...

Use the host and user your hosting panel shows for FTP or SFTP. The Host field also takes host:port, and sftp://, ftpes:// and ftps:// addresses. Many hosts name FTP accounts in full, as demo-user@example.com. A ~ at the start of a folder is your home folder, also in cmd.exe.

The server is named after its host; rename it with sync-servers server edit. It becomes the site's Remote server, the one synchronization uses. Add more servers, such as a staging copy, with sync-servers server add, which asks the same questions; --testing makes one the Testing server.

Ways to reach a server
ProtocolUse it for
sftpMost hosts. Signs in with a password, a private key file, or the SSH agent.
ftpsFTP with TLS started on the usual port (explicit TLS).
ftps-implicitFTP over TLS from the first byte, usually on port 990.
ftpOld hosts only. It sends the password in clear text, so it needs --allow-insecure.
localA folder on this computer, a mounted drive or a network share.

To sign in with a key instead of a password: --auth key --key-path ~/.ssh/id_ed25519. The key file is read when connecting and never copied.

2. What the first connection asks

Setup connects before it saves anything, and asks only what a person has to decide:

When the connection fails, setup says why and offers a fix: another host, the user name and password again, or saving without testing. Cancel saves nothing.

3. Passwords

Once the server accepts the password you typed, setup offers to save it in the operating system's credential store: Windows Credential Manager, the macOS Keychain, or the Secret Service keyring on Linux. It is never written to a file, and a password the server refused is never saved. To save or change it later:

sync-servers password set Production --site "My Site"

Without a saved password you are asked for it when connecting, and an unattended run reads SYNC_SERVERS_PASSWORD. See Secrets.

4. Testing again later

sync-servers server test

The test connects, signs in, checks the root directory, and reports what the server offers: the folder the account opens in, its software, how precise its file times are, and for FTPS the TLS version. With one site, nothing needs naming. In a terminal it also fixes what it finds: a refused sign-in asks for the user name and password again, a root that is not found is picked from what the server shows, and a host that is not found can be changed. Each fix is saved.

To change a server later, sync-servers server edit asks the same questions with the current values as defaults. If sites.json itself stops loading, sync-servers config edit opens it with its problems listed.

5. Cloak what should never move

sync-servers cloak --site "My Site" .psd "archive*" /drafts/
sync-servers cloak --global .git/ node_modules/ Thumbs.db

Cloaked files are never scanned, listed, transferred or deleted, on either side. The first command cloaks for one site; the second, with --global, for every site, so files that belong to no site are cloaked once. Cloaking patterns explains the syntax, and Global patterns how a site can re-include or ignore them.

6. Preview, then synchronize

Inside the site's folder, or with only one site, the site is chosen for you:

cd ~/sites/my-site
sync-servers sync --put

--put sends newer local files to the server, --get fetches newer files from it, and --both does each. Add --delete to also remove files that are missing on the other side.

In a terminal the preview opens full screen. Each row is a file with a difference: a checkbox, an action and a status. c checks or unchecks a row and Space every row, p, g and s choose Put, Get or Skip, d shows the difference, and Enter synchronizes the checked rows after one more question. Esc leaves without changing anything.

 Synchronize: My Site -> Production (SFTP)            Put newer files to remote
 Files: 37 will be updated, 169 will be skipped, 12 need a decision
 ------------------------------------------------------------------------------
  [x] ^ Put      img/hero.svg
  [ ] ? Resolve  css/site.css        Changed locally and on the server since...
  [ ] ^ Put      .env                Matches the sensitive pattern ".env". C...

On a first sync there are no records yet, so a file that differs on both sides and has the same age asks for a decision. Files such as .env and private keys are listed unchecked. Prefer your own editor or numbered prompts? See Preview modes.

To see the preview without transferring anything, add --dry-run. In a script, sync without --yes only prints the preview.

7. Land in a site's folder

A program cannot change its shell's folder, so shell-init prints a small ssv function that does:

eval "$(sync-servers shell-init bash)"     # in ~/.bashrc; zsh is the same
ssv                                        # pick a site, land in its folder

PowerShell, fish and cmd are covered in Shell integration.

Try it without a real server

From a clone, npm run sandbox starts local SFTP, FTPS and FTP servers on 127.0.0.1 with throwaway credentials and prints the commands to add them as servers. Press Ctrl+C to stop them.