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

Pre-prerequisites

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

OpenSSH

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!


pwd

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

~$ pwd

ifconfig

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/>

Example

~$ scp commander@192.168.1.74:/home/commander/code/hatnix.php test/

➼ scp secure copy command
➼ commander remote user name
➼ 192.168.1.74 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>

Example

~$ scp test/nurse.py commander@192.168.1.74:/home/commander/code

➼ local file - This is the file you want to transfer to the remote server
➼ commander - Remote username
➼ 192.168.1.74 - 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/>

Example

~$ scp -r commander@192.168.1.74:/home/commander/code/ test/

Transfer Directory From Local to Remote Server

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

Example

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

YouTube

Facebook

Instagram

Twitter

Twitch
Previous Lesson | Next Lesson