Copying files with the SCP utility
SCP Utility Guide
SSH (Secure Shell) is a secure way to access a server remotely over an encrypted connection. It allows you to manage your VPS, or dedicated server, install software, configure services, and monitor your system directly from the command line.
One of the most useful tools that works over SSH is SCP (secure copy) — a utility and protocol for securely transferring files between computers. With SCP, you can move files between your local machine and a server, or between two remote servers, all over an encrypted connection.
SCP Command Syntax
The basic syntax for copying files looks like this:
$ scp [options] user1@server1:/path/to/directory (SOURCE) user2@server2:/path/to/directory (DESTINATION)
- Options control the behavior of SCP and relate to the underlying SSH protocol.
- Then you specify the source file or directory and the destination path.
- Either path can be on your local machine or a remote server.
- Use a valid user account on the server, and instead of an IP address, you can also use the server’s domain name.
Important
The user must have write permissions for the target directory.
Useful SCP Options
Some SCP options that might come in handy:
-1
— use SSH protocol 1-2
— use SSH protocol 2-B
— batch mode for transferring multiple files-C
— enable compression-l
— limit the transfer speed in Kbit/s-o
— specify an SSH option-p
— preserve modification times-r
— recursively copy directories-v
— verbose mode for debugging
SCP Examples
Recursively copy a directory to your local machine
scp -r root@1.111.1.111:/var/www/user/data/www/site.ru/upload /home/web/test.site.ru/public_html/
This copies all files and directories from /var/www/user/data/www/site.ru/upload
on server 1.111.1.111
to the local folder /home/web/test.site.ru/public_html/
.
Recursively copy a directory between two remote servers
scp -r root@1.111.1.111:/var/www/user/data/www/site.ru/upload root@2.222.2.222:/home/web/test.site.ru/public_html/
This copies all files and directories from /var/www/user/data/www/site.ru/upload
on server 1.111.1.111
to /home/web/test.site.ru/public_html/
on server 2.222.2.222
.
Copy a single file from a remote server
scp root@1.111.1.111:/var/www/user/data/www/site.ru/upload/img.jpg /home/web/test.site.ru/public_html/upload/
This copies the file img.jpg
from /var/www/user/data/www/site.ru/upload
on server 1.111.1.111
to the local folder /home/web/test.site.ru/public_html/upload/
.
Important
The destination directory must end with a trailing slash /
. Otherwise, the copied directory may overwrite the specified path.
Help
If you have any questions or need further assistance, you can contact support via the ticket system or online chat.