An SSH login also provides an encrypted path for files. scp copies a file in either direction between your local machine and an SSH server, using the same host key check and authentication as an interactive login.
Current OpenSSH clients run scp transfers over the SFTP protocol by default while keeping the familiar scp command syntax. The source comes first and the destination last, so the remote account and host appear on the destination for an upload and on the source for a download.
The local machine needs an OpenSSH client, and the server must accept SSH connections with SFTP enabled. The account reading the source needs read permission, while the account receiving the file needs write permission in the destination directory. A checksum and byte count can check the copy without printing a large or binary file in the terminal.
Steps to copy files over SSH with scp:
Run every command in a terminal on your local machine, including downloads; an ssh command runs only its quoted part on the server. The commands use Unix-like shells on both machines. Choose Upload or Download and use that same alternative in each step. The paths refer to a local /home/user/reports/q1.csv and a remote /home/user/uploads/q1.csv; substitute your account, server, and paths.
Accepting an incorrect server host key can expose the transfer to interception. If a first connection asks for trust, confirm the fingerprint through a trusted channel before accepting it. For a non-default port, add -P 2222 to scp or -p 2222 to each ssh command, before the paths or host. Add -i ~/.ssh/deploy_key to either command when a specific private key is required.
Related: How to connect to an SSH server on a different port
- Calculate the source file's checksum from your local machine.
Local to remote (upload)
$ cksum < /home/user/reports/q1.csv 2151865133 25
Remote to local (download)
$ ssh user@host.example.net 'cksum < /home/user/uploads/q1.csv' 2151865133 25
cksum prints the CRC checksum followed by the byte count without displaying the contents. The same check works for text and binary files; the numbers depend on the file's contents.
- Create the destination directory for your chosen direction.
Local to remote (upload)
$ ssh user@host.example.net 'mkdir -p /home/user/uploads'
Remote to local (download)
$ mkdir -p /home/user/reports
Use an existing directory instead when the destination has already been prepared. scp does not create missing parent directories for the target file path.
- Copy the file in your chosen direction from your local machine.
scp overwrites a destination file with the same name without confirmation. If that file must be kept, choose a different destination filename before copying.
Local to remote (upload)
$ scp /home/user/reports/q1.csv user@host.example.net:/home/user/uploads/
Remote to local (download)
$ scp user@host.example.net:/home/user/uploads/q1.csv /home/user/reports/
For multiple files going to the same directory, list the source paths before the destination; each remote source needs its account and host prefix. If an older server lacks SFTP support, scp -O can force the legacy SCP protocol, but that mode uses the remote shell for filename handling and should be treated as a compatibility exception.
- Compare the destination checksum and byte count with the source values.
Local to remote (upload)
$ ssh user@host.example.net 'cksum < /home/user/uploads/q1.csv' 2151865133 25
Remote to local (download)
$ cksum < /home/user/reports/q1.csv 2151865133 25
Both numbers should match the source check from the first step. A mismatch means the files differ; a missing-file or permission error means the destination has not been verified. This CRC check detects accidental corruption and is not a cryptographic authenticity check.