Copying files with SCP
While SSH allows us to send commands to a remote computer, SCP allows us to send files. This can be useful if we want to upload a file to a server as part of an application deploy, or even just to share that file with other people.
The command structure is scp source destination
, where source
and destination
represent either local or remote files. A local file is represented by its file path, and a remote file is represented by username@server:/path/to/file
.
For example, if we wanted to copy a file from our client computer to a server, we can run the following command:
scp my-file.txt william@my-server:/Users/william/Desktop/
The preceding command will send our file named my-file.txt
to the server named my-server
, after logging in with the username william
. The destination path will be /Users/William
/Desktop/my-file.txt
.
If we wanted to copy a directory of files instead of a single file, we could use the -r
command flag to recursively copy an...