File Transfer and Synchronization
Quick answer
Choose scp for straightforward copies, sftp for interactive file transfer, and rsync for synchronizing a tree with controlled updates. Always identify source and destination before running a transfer.
Prepare the practice environment
Run python3 lab-fixtures/ssh-transfer/setup.py from the extracted package root as an ordinary user. Enter the printed private path and check pwd. Use a fresh fixture and Bash with LC_ALL=C and pipefail. Only local rsync and synthetic files are tested here. For manual SSH examples use an isolated authorized VM network, snapshot, console access, provisioned learner account and independently verified host keys; see the lab guide. Never use real credentials or external hosts.
How it works
OpenSSH scp uses SFTP by default since version 9.0; older releases can differ. The colon in user@host:path denotes a remote path. rsync can work entirely locally or use a remote shell; it is not inherently an encrypted protocol. A source trailing slash copies directory contents rather than the containing directory. A dry run previews proposed changes but does not guarantee success. Archive mode preserves many attributes, not all metadata; permissions and filesystem support matter. Avoid deletion flags until policy, preview and recovery are reviewed.
With existing empty destinations, copying source/ places note.txt immediately inside the destination, while copying source places it under a new source subdirectory. Preview each operation before executing it. Compare the intended path and file bytes afterwards; a correct byte comparison does not verify ownership, ACLs or recovery from a lost source.
Try the examples
rsync -ani source/ dest/test ! -e dest/note.txt && printf 'destination unchanged\n'The itemized output shows a new regular file in this fixture.
Expected stdout:
>f+++++++++ note.txtdestination unchangedrsync -a source/ dest/cmp source/note.txt dest/note.txt && printf 'verified\n'cmp compares file contents; it is not a full metadata or backup audit.
Expected stdout:
verifiedscp -o StrictHostKeyChecking=yes -o UserKnownHostsFile=./known_hosts source/note.txt learner@lab-server.example:incoming/VM only; prepare a verified host entry and an empty writable incoming directory. Confirm the remote file after transfer.
Manual example; not executed locally. Follow its stated environment restrictions.
Common mistakes
Do not use --delete as a default, assume a preview is a backup, or overwrite remote files without inspecting the destination.
Practice
Using two fresh destination directories, compare rsync -a source/ dest/ with rsync -a source dest/ and inspect the resulting paths. Verify bytes and explain why the paths differ.
Related references
Study: scp, sftp, rsync. These are reference names, not deployed links.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
File transfer and synchronization — Knowledge Check
Apply SSH trust and transfer concepts to synthetic fixtures and VM-only scenarios.
What does source/ mean in rsync?
What does -n mean in rsync?
Since OpenSSH 9.0, scp defaults to?
Which verifies identical file bytes locally?