Using scp (secure copy) to Copy Files Between Computers

Copy a file from your local computer to a remote host using secure copy, scp (which uses ssh for data transfer and provides the same security as using ssh).

scp [filename] [username]@remotehost:[location]

[bash]scp file_to_copy.txt [email protected]:/some/remote/directory[/bash]

copy a directory to your home computer from the remote computer.

[bash]scp -r directory_to_copy [email protected]:[/bash]

copy a directory from a remote server to the current directory on your computer.

scp -r folder [username]@remotehost:[location] .

[bash]scp -r [email protected]:/some/remote/directory .[/bash]

If you don’t have automated keys setup you will be asked for the password for that user.

An example for copying a MySQL database. Including the : without a location puts the file in the home folder.

[bash]mysqldump database_name -uroot > database_dump.sql
scp database_dump.sql [email protected]:[/bash]

Then ssh into the remote server and open the mysql prompt
[bash]mysql -uroot -p
mysql> create database database_name;
mysql> exit[/bash]

Then run the mysqldump file

[bash]mysql database_name -uuser -p < database_dump.sql[/bash]

Remember to create the database user on the new machine (this has to match what is in the wp-config.php file).

2 thoughts on “Using scp (secure copy) to Copy Files Between Computers

  1. Pingback: Rsync to copy Files Between Servers and Computers | Coding and Server Syntax Examples

  2. Pingback: Chrome Remote Desktop | Coding and Server Syntax Examples

Comments are closed.