Whenever you're working with computers or any electronic device that has storage capacity, you might need to distribute or share information and files in various ways. Some of the most commonly shared files include audio files, images, videos, pdfs or any form of word documents. Most of the time, the information being shared will be private or confidential – meaning it's meant for a specific person or a group of people, so protecting it is
essential. When it comes to devices like mobile phones we have app the facilitate the transfer of files like xender, appshare or even sometimes the use of bluetooth. Now, when it comes to computers the case is not different we have softwares and even sites that facilitate the same. When it comes to sharing data in operating systems like Linux, there are multiple commands you can choose from to share information. But today we'll be focusing on the SCP
command. It lets you share files and data securely and easily. In today's market gap, having Linux skills is very essential and helpful more so if you are a system administrator. As a system admin sharing of data will be among your day to day activity and you will need the data being shared to be safe, and by using SCP command you will be able to achieve this. Before we get started, let's begin by understanding what SCP is, and then we'll learn some commands you can use for file
transfer. What are SCP Commands?SCP is an acronym for Secure Copy Protocol. It is a command line utility that allows the user to securely copy files and directories between two locations usually between unix or linux systems. The protocol ensures the transmission of files is encrypted to prevent anyone with suspicious intentions from getting sensitive information. In simpler words we can say that SCP is a safer option for the It is also important to note that SCP uses encryption over an SSH (Secure Shell) connection, this ensures that the data being transferred is protected from suspicious attacks. SCP SyntaxJust like any other commands used in the terminal, the SCP also have a format that is used for a successful execution to happen. By understanding the syntax it makes it easier for you to write down the commands:
Since we are dealing with file transmission, it definitely means that there have to be an involvement of more than one machine to make the process possible. We are able to use SCP in the following cases:
At this point, it will be fair to state that before you use any SCP commands you will need to have a few things in place:
With two thing's ready you are good to go. Let's get started by seeing the commands in action. Common SCP CommandsCopy File From Local Host to Remote ServerWhen copying files, being able to transfer files/data from local storage to remote server is very essential. When using the SCP commands you will need to specify a few things for this to happen. You will have to specify the path to the file as the source and also specify the remote host path, where the files are being copied to. Let's take a scenario where we have a file
We are not limited to the number of files we can copy. Let's say we
are on our desktop in the folder called web where we have
*.php - copies all the files with the .php extension in the currently specified folder. Let's say you wanted to copy a file named test.txt and save it with a different name in the remote server this time round using an option of port. The command will be:
In this example we have copied a file test.txt from local machine into remote where it will be saved as test2.txt using port 8080. Copy Files From Remote to LocalA better way to understand this is by use of an example. Take a scenario where you want to copy files from remote system. To copy the files you will need to first invoke the SCP, followed by the remote username@IP address, path to file. If you do not specify the path, it is assumed as default in this case which will be the user's home directory, this will be followed the path where the file will be stored locally. The Syntax
Let's say I wanted to copy a file named linuxcheatsheet from the remote device with this address 192.168.1.100. The linuxcheatsheet file is stored on the kali user’s home directory, the user I will authenticate. Therefore after the colon, I don’t need specify the path because it's the default one, which is the home directory, and I just type the filename (“linuxcheatsheet”). Then, I specify the current directory as the local location to store the file by typing a dot.
Copy Files From Remote Host to AnotherThe beauty of using SCP in file transferring, is that it does not only allow connection between local machines but also it allows for you to connect to remote servers. Let's say we wanted to copy a file named test.txt, to another remote server the command would look like below:
What this command will do is copy test.txt from files folder in the the user1 and create a replicate of it in user2 which runs on host2.com still on the files folder. Copying Multiple FilesWhen copying multiple files, all you need to do is specify the file name as the source path. for example. The Syntax
Let's say we wanted to copy files 1,2,3 and 4. The command would look like below:
Takeaway Points:
Wrap UpWhether you are a support engineer, system admin, or even a growing developer like myself who uses Linux or wants to learn it – it's likely that you will have to transfer files at some point. And knowing these simple SCP commands will come in handy. In this article, we have covered some of the most common scenarios where you'd want to use SCP and hopefully you have learned something new. Enjoy Coding ❤ Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. Get started How do I transfer files from local to SSH?Transferring Files Via SSH Across Remote Servers. Use your remote servers' web console to log in. Access their control panels and check that SSH is enabled. ... . Start Putty and set up your SSH remote server connection. ... . Find the destination folder you're looking for on the remote server (through Putty). ... . 4 Comments.. How move file from local to remote in Linux?To copy the files you will need to first invoke the SCP, followed by the remote username@IP address, path to file. If you do not specify the path, it is assumed as default in this case which will be the user's home directory, this will be followed the path where the file will be stored locally.
How do I copy a folder from local to remote SSH?Copy directory and files from local to remote server. You can use either scp or rsync to copy folder and files from local to ssh or copy folder and files from ssh to local within in the same or different directory. By default copy files and folders happen sequentially.
How do I copy a local file to a remote server?How to Copy a File from/to a Remote Server. scp [email protected]:/remote/path/to/file /local/path.. scp -r [email protected]:/remote/path/to/directory /local/path.. scp /local/file/path username@example:/remote/path.. scp -r /local/directory/path username@example:/remote/directory/path.. |