Upload file on Linux Ubuntu Server using SCP

Linux server provides a terminal to manage the server. Sometimes you need to upload file or folder or directory on the Linux Server. Using your terminal, you can upload files and folder directly to your server by SCP command. Here we are providing the way to upload file on Linux Server using SCP.

The basic command structure is as follow:

scp <Local File> <Server Username>@<Host>:<Path on Server>

Now take some different type of examples for different situations to upload file on the server.

1. Upload a single file

scp ~/Desktop/sample.txt ubuntu@devstudioonline.com:/home/ubuntu/myfiles

Here you will be asked for the password of the server.

2. Upload a Directory or Folder

scp -r ~/Desktop/myfiles ubuntu@devstudioonline.com:/home/ubuntu/myfiles

Here myfiles is a directory and I have added -r for recursive file transfer.

3. Server SSH have different port

scp -r -P 9001 ~/Desktop/myfiles ubuntu@devstudioonline.com:/home/ubuntu/myfiles

Here -P 9001 is for the specified port.

4. The server has a Private Key File like pem or ppk to connect

scp -r -P 9001 -i ~/Desktop/server.pem ~/Desktop/myfiles ubuntu@devstudioonline.com:/home/ubuntu/myfiles

Here server.pem is my Private Key file to authenticate the server.

5. Upload current directory to the server

scp -r -P 9001 -i ~/Desktop/server.pem . ubuntu@devstudioonline.com:/home/ubuntu/myfiles

Here I have used . for the local address to locate the working directory

If you have any other situation to upload file on the Linux server then comment us the situation. 

To download files read the article:

Download file on Linux Ubuntu Server using SCP

Keywords: