Transfer Files Command Line

In this lesson we will use the scp command line tool to transfer files and folders.

Command Line File Transfer Video Tutorial


Here are some commands and software that will faciliate the lesson.


To log into a remote server from our local machine, we will use SSH. If you are using my tutorals, this is a great way to access your virtual server from your local environment. If you use windows you may use puTTY to SSH into a remote server. If you use Linux, just open your terminal application and you are good to go!

To Install OpenSSH on Ubuntu:

~$ sudo apt update
~$ sudo apt install openssh-server
~$ sudo apt install openssh-client

To verify SSH works

~$ sudo systemctl status ssh

If it says the server is "active (running)", you are all set!


Not sure the location of your file or directory? the pwd command with give you the present working directory.

~$ pwd


When using SSH or SCP, you must specify your host. You can do this by host name or ip address. The ifconfig command is handy for checking your ip.

~$ ifconfig

Mouse Hover over the ➼ blue text in the descriptions to highlight the command above.

Transfer File From Remote Server to Local Server

~$ scp <remote_user_name>@<remote_host>:</remote_file_location> <destination/>


~$ scp commander@ test/

➼ scp secure copy command
➼ commander remote user name
➼ remote host (ip address)
➼ File Location of the remote file you wish to copy
➼ test/ The local destination for the file.

Transfer File From Local to Remote Server

~$ scp <file_location> <remote_username>@<remote_host>:<remote_destination>


~$ scp test/ commander@

➼ local file - This is the file you want to transfer to the remote server
➼ commander - Remote username
➼ - Remote host (ipaddress)
➼ destination - The directory on the remote server where you want to put your local file.

Transfer Directory From Remote Server to Local Server

To transfer directories, we use -r. -r is the recursive argument in Linux commands. That means the command will effect that directory as well as all the files and directories located within that directory.

~$ scp -r <remote_user_name>@<remote_host>:<remote_directory_location> <destination/>


~$ scp -r commander@ test/

Transfer Directory From Local to Remote Server

~$ scp -r <directory_location> <remote_user_name>@<remote_host>:<remote_destination/>


~$ scp -r test/ commander@
Follow Coding Commanders on:





Previous Lesson | Next Lesson