Transferring files with SCP

SCP stands for Secure Copy Protocol it's based on SSH which allows us to access the remote system over the secure connection. The Good thing about SSH is we can connect to the remote system and execute the commands.
Copying files from Local Machine to Remote Server with SCP
This is really helpful when you have to copy any files from the local machine to the remote server or vise versa. If you love GUI you can use programs like Filezilla to copy the files over the FTP.
Copying files in the Terminal with SCP is really easy.
All you have to do is Open the terminal can enter the command.
scp /home/letsfoss/myfolder root@SERVER-IP:/var/www/folder
The above command is for copying the folder contents from the local machine to the remote server.
Let's break down the command.
scp
is the program which helps to perform the file copying operation./home/letsfoss/myfolder
is the local folder which I want to copy into the serverroot@SERVER-IP
root is my SSH username and SERVER-IP is the actual server IP:/var/www/folder
This is the path on the remote server where I want to copy all the contents from the local machine.
Once you have all the information, press the Enter key and you'll be prompted with a password input.
Enter your password and press enter key to start copying from the local machine to the remote server with SCP.
Copying files from Remote Server to Local Machine with SCP
For transferring the files from the remote server to the local machine we have to alter the command a bit.
scp root@SERVER-IP:/var/www/myapp /home/letsfoss/myapp
When transferring the files from a remote server to the local machine we have to specify the server IP in the first argument and the local path in the second argument.
Break down of the above command
scp
- Program which allows us to securely transfer the filesroot@SERVER-IP
- Actual SSH username and Server IP/var/www/myapp
- Path of the folder or file in the remote server/home/letsfoss/myapp
- Path of the folder or file in the local machine
Make sure you have :
colon in between the server IP and server folder path
If you have any doubts, feel free to comment below.
Related Articles



