Repository navigation
Expand file tree
/
Copy pathgetting-started.html
More file actions
154 lines (145 loc) · 13.1 KB
/
Copy pathgetting-started.html
File metadata and controls
154 lines (145 loc) · 13.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'self'; img-src 'self'; base-uri 'none'; form-action 'none'">
<meta name="description" content="Create a site and its server in one command, decide what the first connection asks, and run the first preview.">
<title>Getting started | cmd-sync-servers</title>
<link rel="stylesheet" href="assets/site.css">
</head>
<body>
<a class="skip" href="#main">Skip to the content</a>
<header class="site-header">
<div class="inner">
<a class="brand" href="index.html">cmd-sync-servers</a>
<nav aria-label="Pages">
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="quickstart.html">Quickstart</a></li>
<li><a href="getting-started.html" aria-current="page">Getting started</a></li>
<li><a href="examples.html">Examples</a></li>
<li><a href="cheatsheets.html">Cheatsheets</a></li>
<li><a href="configuration.html">Configuration</a></li>
<li><a href="cli.html">Command line</a></li>
<li><a href="options.html">Options</a></li>
<li><a href="synchronization.html">Synchronization</a></li>
<li><a href="api.html">Library API</a></li>
<li><a href="security.html">Security</a></li>
<li><a href="troubleshooting.html">Troubleshooting</a></li>
</ul>
</nav>
</div>
</header>
<main id="main">
<h1>Getting started</h1>
<p class="lead">From nothing to a first synchronization: a site and its server in one command, then a preview.</p>
<p>Every step below works two ways. In a terminal, run <code>sync-servers</code> 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.</p>
<h2 id="site">1. Create a site and its server</h2>
<p>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:</p>
<pre><code>sync-servers site add --name "My Site" --local-root ~/sites/my-site \
--protocol ftps --host 203.0.113.10 --user demo-user@example.com</code></pre>
<p>On Windows, in <code>cmd.exe</code>:</p>
<pre><code>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</code></pre>
<p>Or run <code>sync-servers site add</code> alone and answer the questions:</p>
<pre><code>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...</code></pre>
<p>Use the host and user your hosting panel shows for FTP or SFTP. The Host field also takes <code>host:port</code>, and <code>sftp://</code>, <code>ftpes://</code> and <code>ftps://</code> addresses. Many hosts name FTP accounts in full, as <code>demo-user@example.com</code>. A <code>~</code> at the start of a folder is your home folder, also in <code>cmd.exe</code>.</p>
<p>The server is named after its host; rename it with <code>sync-servers server edit</code>. It becomes the site's <strong>Remote</strong> server, the one synchronization uses. Add more servers, such as a staging copy, with <code>sync-servers server add</code>, which asks the same questions; <code>--testing</code> makes one the <strong>Testing</strong> server.</p>
<table>
<caption>Ways to reach a server</caption>
<thead><tr><th scope="col">Protocol</th><th scope="col">Use it for</th></tr></thead>
<tbody>
<tr><td><code>sftp</code></td><td>Most hosts. Signs in with a password, a private key file, or the SSH agent.</td></tr>
<tr><td><code>ftps</code></td><td>FTP with TLS started on the usual port (explicit TLS).</td></tr>
<tr><td><code>ftps-implicit</code></td><td>FTP over TLS from the first byte, usually on port 990.</td></tr>
<tr><td><code>ftp</code></td><td>Old hosts only. It sends the password in clear text, so it needs <code>--allow-insecure</code>.</td></tr>
<tr><td><code>local</code></td><td>A folder on this computer, a mounted drive or a network share.</td></tr>
</tbody>
</table>
<p>To sign in with a key instead of a password: <code>--auth key --key-path ~/.ssh/id_ed25519</code>. The key file is read when connecting and never copied.</p>
<h3 id="dreamweaver">A folder Dreamweaver synchronized</h3>
<p>Dreamweaver leaves its synchronization records in the site's folders, as <code>_notes/dwsync.xml</code> files. When the local folder holds some, <code>site add</code> asks whether to use them, once the server is set up:</p>
<pre><code>This folder holds Dreamweaver synchronization records (_notes/dwsync.xml).
Use them, and keep them up to date for Dreamweaver? (Y/n):
Dreamweaver synchronized this folder with these servers. Which one is server1.hosting.example.net?
1. 203.0.113.10//public_html/ (212 files)
2. D:/Sites/my-site-testing/ (198 files)
3. None of these
Choose a number [3]: 1
Reading Dreamweaver's records...
Added site "My Site" with the server server1.hosting.example.net (FTPS). It is the Remote server.
Took 204 files as in sync from Dreamweaver's records.</code></pre>
<p>The second question comes only when Dreamweaver knew the server by another name than its host and folder give here. With a yes, the files Dreamweaver last synchronized are in sync from the first preview, and every transfer keeps Dreamweaver's records up to date, so you can go on using both. Without a terminal, the site uses the records when the folder holds some; <code>--no-dreamweaver</code> leaves them alone, and <code>--dreamweaver-server</code> names the server. For a site added earlier, run <code>sync-servers site edit --dreamweaver</code>. <a href="configuration.html#dreamweaver">Dreamweaver synchronization files</a> has the details.</p>
<h2 id="first-connection">2. What the first connection asks</h2>
<p>Setup connects before it saves anything, and asks only what a person has to decide:</p>
<ul>
<li><strong>An SSH host key</strong> seen for the first time is shown, such as <code>ssh-ed25519 SHA256:...</code>. Compare it with the fingerprint your host publishes, then trust it. It is pinned in the server's settings; if it ever changes, the connection stops and both fingerprints are shown. See <a href="security.html#host-keys">Host keys</a>.</li>
<li><strong>A TLS certificate</strong> that does not verify is shown with the names it covers. On shared hosting it often names the hosting company's machine, such as <code>server1.hosting.example.net</code>, and setup offers to connect to that name instead. See <a href="security.html#certificates">Certificates</a>.</li>
<li><strong>The folder that holds the site</strong> is picked from what the server shows, starting where the account opens. Every folder is numbered, in columns when the terminal is wide enough, and folders whose names start with a dot come last:
<pre><code>Signed in as demo-user@example.com. The account opens in "/", which holds:
1. access-logs/ 5. mail/ 9. .cache/ 13. .trash/
2. bin/ 6. public_ftp/ 10. .config/
3. etc/ 7. public_html/ 11. .local/
4. logs/ 8. tmp/ 12. .ssh/
and 23 files
Site root on the server: Enter for "/", a number to open a folder, or a path [/]:</code></pre>
A number opens that folder and lists it, <code>..</code> goes up, and a name or path is taken as typed once it exists; Enter takes the folder shown. Many hosting accounts open in their own folder and see it as <code>/</code>; a path from the control panel does not exist for them.</li>
<li><strong>Deletes at the top.</strong> When the site's folder is the top of what the account sees, setup asks once whether synchronizing may delete files there. Every delete is still listed in the preview first.</li>
</ul>
<p>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.</p>
<h2 id="password">3. Passwords</h2>
<p>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:</p>
<pre><code>sync-servers password set Production --site "My Site"</code></pre>
<p>Without a saved password you are asked for it when connecting, and an unattended run reads <code>SYNC_SERVERS_PASSWORD</code>. See <a href="configuration.html#secrets">Secrets</a>.</p>
<h2 id="test">4. Testing again later</h2>
<pre><code>sync-servers server test</code></pre>
<p>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.</p>
<p>To change a server later, <code>sync-servers server edit</code> asks the same questions with the current values as defaults. If <code>sites.json</code> itself stops loading, <code>sync-servers config edit</code> opens it with its problems listed.</p>
<h2 id="cloak">5. Cloak what should never move</h2>
<pre><code>sync-servers cloak --site "My Site" .psd "archive*" /drafts/
sync-servers cloak --global .git/ node_modules/ Thumbs.db</code></pre>
<p>Cloaked files are never scanned, listed, transferred or deleted, on either side. The first command cloaks for one site; the second, with <code>--global</code>, for every site, so files that belong to no site are cloaked once. <a href="configuration.html#cloaking">Cloaking patterns</a> explains the syntax, and <a href="configuration.html#global-cloaking">Global patterns</a> how a site can re-include or ignore them.</p>
<h2 id="preview">6. Preview, then synchronize</h2>
<p>Inside the site's folder, or with only one site, the site is chosen for you:</p>
<pre><code>cd ~/sites/my-site
sync-servers sync --put</code></pre>
<p><code>--put</code> sends newer local files to the server, <code>--get</code> fetches newer files from it, and <code>--both</code> does each. Add <code>--delete</code> to also remove files that are missing on the other side.</p>
<p>To send only the files created or modified lately, such as in the last two days, give a <a href="synchronization.html#range">time range</a>:</p>
<pre><code>sync-servers sync --put recent --range 2d</code></pre>
<p>In a terminal the preview opens full screen. Each row is a file with a difference: a checkbox, an action and a status. <kbd>c</kbd> checks or unchecks a row and <kbd>Space</kbd> every row, <kbd>p</kbd>, <kbd>g</kbd> and <kbd>s</kbd> choose Put, Get or Skip, <kbd>d</kbd> shows the difference, and <kbd>Enter</kbd> synchronizes the checked rows after one more question. <kbd>Esc</kbd> leaves without changing anything.</p>
<pre><code> 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...</code></pre>
<p>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 <code>.env</code> and private keys are listed unchecked. Prefer your own editor or numbered prompts? See <a href="cli.html#preview-modes">Preview modes</a>.</p>
<p>To see the preview without transferring anything, add <code>--dry-run</code>. In a script, <code>sync</code> without <code>--yes</code> only prints the preview.</p>
<h2 id="folder">7. Land in a site's folder</h2>
<p>A program cannot change its shell's folder, so <code>shell-init</code> prints a small <code>ssv</code> function that does:</p>
<pre><code>eval "$(sync-servers shell-init bash)" # in ~/.bashrc; zsh is the same
ssv # pick a site, land in its folder</code></pre>
<p>PowerShell, fish and cmd are covered in <a href="cli.html#shell-integration">Shell integration</a>.</p>
<h2 id="sandbox">Try it without a real server</h2>
<p>From a clone, <code>npm run sandbox</code> starts local SFTP, FTPS and FTP servers on <code>127.0.0.1</code> with throwaway credentials and prints the commands to add them as servers. Press <kbd>Ctrl</kbd>+<kbd>C</kbd> to stop them.</p>
</main>
<footer class="site-footer">
<div class="inner">
<p>cmd-sync-servers is open source under the MIT license. Source, issues and releases are on <a href="https://github.com/isocialPractice/cmd-sync-servers">GitHub</a>.</p>
</div>
</footer>
</body>
</html>