Using SCP to transfer files from the remote server to your computer and vice versa
Background
I’m doing server migration from DigitalOcean to AWS. I have exported the Mysql database from the Digitalocean Droplet using Mysqldump. I want to download this file to my computer using the terminal/command line and then upload it to the new server.
Problem Statement
How do I download this huge exported SQL file from the old server to my computer then upload it from my computer to AWS without using FileZilla?
Download file from remote to my computer
To download the file remotely from the server using your terminal. Open your terminal and you can use the command below.
scp -i “key_file.pem” your_username@remotehost.com:/remote/dir/foobar.txt /local/dir
- “key_file.pem” is your connection file
- your_username is your username. The common defaults are ubuntu or root any other user you are connecting with
- remotehost.com is your server host or your IP
- /remote/dir/foobar.txt is the path to your file on your server
- /local/dir is the part you want to download it to on your computer
Upload file from my computer to the remote server using terminal
You can upload files from your computer to the remote server using this command
scp -r -i “key_file.pem” foobar.txt your_username@remotehost.com:/this/path/dir
- “key_file.pem” is your connection file
- your_username is your username. The common default is ubuntu or root any other username you are connecting with
- remotehost.com is your server host or your IP
- foobar.txt is the file or path to the file on your computer that you want to upload.
- /this/path/dir is the part you want to upload the file to on your computer
Hit a Permission denied Bump? No worries
The /this/path/dir you are uploading the file to on your server needs to have permission 777
command
sudo chmod 777 /this/path/dir
Run the command to upload again and it should be fine now.
Conclusion:
With SCP (Secure Copy) you can safely upload and download files using your command line/Terminal. I find out that It is much faster than using Filezilla or any other FTP also.
Happy Coding guys