Tag Archives: SCP

SCP Command use tips and tricks

scp command

What is SCP

scp stands for secure cp (copy), which means you can copy files across ssh connection(securely encrypted). It is a very secure way to copy files between computers.

It uses by default the port 22, and connect via an encrypted connection using SSH, in short it using all security setting applied for an ssh connections, for transferring data over network during copy of file from one host to another.

When copying a source file to a target file which already exists, scp will replace the contents of the target file (keeping the inode).

scp have various options, which can be specified over command line.

Few Examples of Scp Commands

Copy one single local file to a remote destination

scp [options [-r Recursively copy entire directories]] /path/to/source-file username@hostname:/path/to/destination-folder/

So, if you want to copy the file /home/user/table.csv to a remote host named host.example.com and copy there to abhishek’s home folder, use this command.

scp /home/user/table.csv username@host.example.com:/home/abhishek/

Copy one single file from a remote server to your current local server

scp username@hostname:/path/to/source-file /path/to/destination-folder

example body could be similar to .
scp username@host.deliverchoices.co.in:/home/abhishek/table.csv /home/abhishek/

You can copy multiple file from host to remote by just replacing file name with ‘directory-name/*’ options.

Copy one single file from a remote server to another remote server

With scp you can copy files between remote servers from a third server without the need to ssh into any of them, all weight lifting will be done by scp itself.

scp user1@server1:/path/to/file user2@server2:/path/to/folder/

Copy multiple files with one command

You can copy multiple files at once without having to copy all the files in a folder, or copy multiple files from different folders putting them in a space separated list.

scp file1.txt file2.txt file3.txt username@host.deliverchoices.co.in:/home/abhishek/

Copy all files in a folder recursively to a remote server

scp -r /home/abhishek/html/* username@host.deliverchoices.co.in:/home/abhishek/newfolder/