[HOW-TO] Transfer a file to server, via SSH: scp
February 1, 2022•387 words
Secure Copy Protocol (SCP) allows you to transfer files from one location to another, either to a local or remote server
scp [flags] [path/to/local.file] [username]@[0.0.0.0]:[/path/to/destination.file]
Where [username] is your account username, [0.0.0.0] is your servers IP, the first path is from, and the second path is to, and [flags] can contain any of the options below.
Done using scp (or secure copy)
EXAMPLE
Uploads a HTML page from the current directory to a remote location
scp -P 2200 404.html asykes@167.99.88.174:/home/asykes/node-apps/alicia.ht/404.html
Downloads the SmokePing Configuration directory into a local folder
scp -P 2200 -r alicia@192.168.130.2:~/smokeping/config/ ./smokeping
FULL DOCS
https://linux.die.net/man/1/scp
FLAGS
-1
Forces scp to use protocol 1.
-2
Forces scp to use protocol 2.
-4
Forces scp to use IPv4 addresses only.
-6
Forces scp to use IPv6 addresses only.
-B
Selects batch mode (prevents asking for passwords or passphrases).
-C
Compression enable. Passes the -C flag to ssh(1) to enable compression.
-c
cipher. Selects the cipher to use for encrypting the data transfer. This option is directly passed to ssh(1).
-F
sshconfig Specifies an alternative per-user configuration file for ssh. This option is directly passed to ssh(1).
-i
identityfile Selects the file from which the identity (private key) for public key authentication is read. This option is directly passed to ssh
-l
limit Limits the used bandwidth, specified in Kbit/s.
-o
ssh_option (see docs)
-P
port Specifies the port to connect to on the remote host
-p
Preserves modification times, access times, and modes from the original file.
-q
Quiet mode: disables the progress meter as well as warning and diagnostic messages from ssh(1).
-r
Recursively copy entire directories. Note that scp follows symbolic links encountered in the tree traversal.
-S
program Name of program to use for the encrypted connection. The program must understand ssh(1) options.
-v
Verbose mode. Causes scp and ssh(1) to print debugging messages about their progress. This is helpful in debugging connection, authentication, and configuration problems.
DIFFERENCE BETWEEN SCP AND SFTP
SCP is the faster of the two, but SFTP offers additional functionality- for moving, deleting, listing and renaming files and directories on a remote origin, SFTP also supports pausing/ resuming of file transfers. Both protocols encrypt for data-in-motion and provide public key authentication, and both support large files transfers, with no size limits.