Psychz - Purnima
Votes: 0Posted On: Nov 05, 2019 12:36:17
SCP stands for a secure copy(cp), which means you can copy files across SSH connection between computers. Since SCP uses SSH protocol, tt is a very secure way to copy files between computers as SSH (Secure Shell) is a cryptographic network protocol for operating network services securely over an unsecured network. It is included by default in most Linux and Unix distributions. By default, SCP uses the port 22, and connect via an encrypted connection or secure shell connection. You can also copy files directly from one remote server to another remote server using SCP. SCP is very versatile and can be used on Linux, Mac, and Windows (using WinSCP).
We are going to start with some basic commands and examples here.
The following syntax is used to copy a file from the source to a destination.
#
scp
source_file_path destination_file_path
Depending on the type of host, the above syntax will also need a file path with full host address, port number, username and password along with the directory path.
So if you want to send file from your local machine to a remote machine the syntax would look like this
# scp /local_machine_file.txt user@172.212.xxx.xxx:/some/remote/directory
This will be reverse when copying file from remote host to local host.
# scp user@172.212.xxx.xxx:/some/remote/directory /local_machine_file.txt
just download the file
# s
cp
user@172.212.xxx.xxx:/some/path/file.txt
NOTE: By default scp will always overwrite files on the destination.
The following syntax will guide you to copy the same file from user1 home folder to user2 home folder in another remote machine.
# scp user1@152.144.xxx.xxx:/home/file.txt user2@172.168.xxx.xxx:/home/
Now, with the following syntax we will see how to Copy one single file from a remote host to the same remote host in another location
# scp user1@152.144.xxx.xxx:/home/file.txt user2@152.144.xxx.xxx:/home/
Now we will see how to Copy the directory "demo_dir" from the local host to a remote host's directory "location"
# scp -r demo_dir user1@152.144.xxx.xxx:/remote/directory/location
We will see now how to copy multiple files using scp 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 user1@172.165.xxx.xxx:/home/user1/
If you want to copy multiple files that are located in different folders you need to specify the complete path.
# scp /path/to/file1.txt /path/to/file2.txt /path/to/file3.txt user1@172.165.xxx.xxx:/home/user1/
The following syntax will copy all files of a given extension to the remote server. For instance, you want to copy all your text files (txt extension) to a new folder. Here we will use a wildcard asterisk (*) to simplify the task.
# scp /home/user/*.txt user1@172.165.xxx.xxx:/home/user1/
Copy all files in a folder with any extension to a remote server. This will copy all files inside local folder to the remote folder. Here's an example.
# scp /home/user/html/* jane@host.example.com:/home/jane/backup/
Other available GUI based tools available for using SCP
WinSCP
If you are working on a Windows powered computer, you can still enjoy scp in various ways. Winscp is a powerful GUI tool available used by a large number of user base that use windows platform.
pscp
pscp is a shell command that works almost on Windows Shell the same way that scp works on Linux or Mac OS X