How to send files using SCP and SSH
- EN
- ES
Table of Contents
#
What is SCP?
If you need to transfer files quickly and securely between two machines using SSH
, scp
(Secure Copy Protocol) is the ideal command-line tool for the job. Designed for encrypted transfers, it is simple to use and highly effective, especially for one-off tasks.
The basic structure of an scp
command is:
scp [options] <source> <destination>
#
What do you need before using SCP?
Before transferring files with scp
, you need to make sure you can authenticate to the remote server using SSH. This can be done in two main ways:
- With a password: When you run
scp
, you will be prompted for the remote user’s password. - With SSH keys: Set up a public key on the remote server (usually in
~/.ssh/authorized_keys
) and use your local private key to authenticate without a password. This is more secure and convenient for frequent use.
To test the connection, use:
ssh user@server
#
Some practical examples
Send a file to a remote server
scp file.txt user@server:/remote/path/
This command will send file.txt
to the remote server at the specified path.
Download a file from a remote server
scp user@server:/remote/path/file.txt /local/path/
This will download file.txt
to your local machine.
Transfer entire directories
To copy a directory, use the -r
(recursive) option:
scp -r directorio user@server:/remote/path/
Specify a different SSH port
If the server uses an SSH port other than the default (22
), add -P
followed by the port number:
scp -P 2222 file.txt user@server:/remote/path/
Transfer files directly between two remote servers
scp user1@server1:/remote/path/file.txt user2@server2:/remote/path/
#
Conclusion
scp
is a simple yet powerful tool for quick file transfers. If you’re looking for more flexibility or need to resume interrupted transfers, consider alternatives like rsync
.