SCP Command to copy files to new server

To copy files from one server to another using scp (Secure Copy Protocol), you’ll need SSH access to both the source and the destination servers. The scp command can be used to securely transfer files between hosts on a network. Here’s the basic syntax to copy files from your local machine to a remote server:

scp [OPTION] [user@]SRC_HOST:]file1 [user@]DEST_HOST:]file2

Here are some examples of how you can use scp:

  1. Copying a file from your local machine to a remote server:
   scp /path/to/local/file username@remote_server:/path/to/remote/directory

This command copies a file from your local machine to the specified directory on the remote server. Replace /path/to/local/file with the path to the file you want to copy, username with your username on the remote server, remote_server with the IP address or hostname of the remote server, and /path/to/remote/directory with the destination directory on the remote server.

  1. Copying a file from a remote server to your local machine:
   scp username@remote_server:/path/to/remote/file /path/to/local/directory

This does the opposite of the first example: it copies a file from the remote server to your local machine.

  1. Copying a directory recursively from your local machine to a remote server:
   scp -r /path/to/local/directory username@remote_server:/path/to/remote/directory

The -r option is used to copy directories recursively. Replace /path/to/local/directory with the path to the local directory you want to copy, and adjust the other placeholders as in the previous examples.

  1. Copying a file from one remote server to another remote server:
   scp username1@remote_server1:/path/to/file username2@remote_server2:/path/to/directory

This command copies a file directly between two remote servers. You will need to have SSH access from the source server to the destination server for this to work without prompting for a password mid-transfer.

Remember to replace placeholders like username, remote_server, /path/to/local/file, and /path/to/remote/directory with your actual user names, server addresses, and file paths. If the SSH server is running on a port other than the default (22), you can specify the port with the -P option, like so: scp -P port_number ....

Leave a Comment

Scroll to Top