Do you need to download files, images, or assets from a VPS server to your local computer? Or perhaps you want to upload Laravel storage files from local to an Ubuntu server?
You can securely complete both tasks with SCP file transfer. The scp command copies files through SSH, which means your data remains encrypted while moving between your computer and a VPS, Ubuntu server, or AWS EC2 instance.
In this practical guide, you will learn how to:
- Download images and assets from a VPS server to local
- Download an entire directory from Ubuntu or AWS EC2
- Upload local files and folders to a remote server
- Transfer Laravel
storage/app/publicfiles - Use an SSH
.pemprivate key with SCP - Fix permission, path, and authentication errors
- Choose between SCP and rsync for large transfers
Replace
YOUR_SERVER_IP, usernames, private-key names, and project paths with your actual information. Never publish or commit a real private key.
What Is SCP File Transfer?
SCP (Secure Copy Protocol) is a command-line tool for securely copying files between computers over SSH.
Remote server → Local computer = Download
Local computer → Remote server = UploadIts basic syntax is:
scp [options] source destination| Option | Purpose |
|---|---|
-r | Copies a folder and everything inside it |
-i | Specifies an SSH private key such as a PEM file |
-P | Uses a custom SSH port; uppercase P is required |
-C | Enables compression during transfer |
-v | Displays detailed output for troubleshooting |
Download Files from VPS Server to Local Using SCP
To download files from a VPS server to your local computer, put the remote source first and the local destination second.
Run this from the terminal on your local macOS or Linux computer:
scp -i "~/keys/laravel-server.pem" \
ubuntu@YOUR_SERVER_IP:/var/www/project/example.jpg \
~/Downloads/This downloads example.jpg from the server and saves it in your local Downloads directory.
The general pattern is:
scp -i "PATH_TO_KEY" USER@SERVER:/REMOTE/FILE /LOCAL/DESTINATION/Download Images and Assets from VPS Server to Local
Web applications often store uploaded images, documents, and public assets inside a directory. Add -r to download an image or assets folder from the server to local:
scp -r -i "~/keys/laravel-server.pem" \
ubuntu@YOUR_SERVER_IP:/var/www/project/public/images \
~/Downloads/project-imagesThis is useful when you need to:
- Back up website images locally
- Move assets to a new VPS
- Inspect production uploads during development
- Download client documents or media files
- Copy files before migrating a server
Replace the remote images path with the correct directory for your website.
Download Laravel Storage Files from Server
Laravel commonly stores generated files and user uploads in:
/var/www/project/storage/appTo download the Laravel storage folder from an Ubuntu server to local, run:
scp -r -i "~/keys/laravel-server.pem" \
ubuntu@YOUR_SERVER_IP:/var/www/project/storage/app \
~/Downloads/project-storageThe command connects as ubuntu, authenticates with the PEM key, downloads the complete storage/app directory, and saves it locally as project-storage.
Download Only Laravel Public Storage Files
To download product images, profile pictures, invoices, and other public uploads without copying private storage files, use:
scp -r -i "~/keys/laravel-server.pem" \
ubuntu@YOUR_SERVER_IP:/var/www/project/storage/app/public \
~/Downloads/laravel-public-filesUpload Files from Local Computer to VPS Server
For an upload, reverse the order: put the local source first and the remote destination second.
scp -i "~/keys/laravel-server.pem" \
~/Downloads/example.jpg \
ubuntu@YOUR_SERVER_IP:/var/www/project/public/images/The general pattern is:
scp -i "PATH_TO_KEY" /LOCAL/FILE USER@SERVER:/REMOTE/DESTINATION/You do not need to log in with SSH first. SCP opens its own SSH connection.
Upload a Folder from Local to Ubuntu Server
Add -r when uploading an entire directory:
scp -r -i "~/keys/laravel-server.pem" \
~/Downloads/project-images \
ubuntu@YOUR_SERVER_IP:/var/www/project/public/The resulting server path will normally be:
/var/www/project/public/project-imagesTo upload only the contents of the local folder into an existing remote directory, add /. to the source:
scp -r -i "~/keys/laravel-server.pem" \
~/Downloads/project-images/. \
ubuntu@YOUR_SERVER_IP:/var/www/project/public/images/This avoids creating an unwanted nested directory.
Upload Laravel Storage Files from Local to Server
Use the following command to upload Laravel public-storage files:
scp -r -i "~/keys/laravel-server.pem" \
~/Downloads/project-storage/app/public \
ubuntu@YOUR_SERVER_IP:/var/www/project/storage/app/The final remote path should be:
/var/www/project/storage/app/publicAfter uploading, connect and verify the files:
ssh -i "~/keys/laravel-server.pem" ubuntu@YOUR_SERVER_IP
ls -lah /var/www/project/storage/app/publicTransfer Files Between Local and AWS EC2 Using SCP
You can use an AWS EC2 public DNS hostname instead of an IP address:
scp -r -i "~/keys/aws-ec2.pem" \
ubuntu@ec2-xx-xx-xx-xx.ap-south-1.compute.amazonaws.com:/var/www/project/storage/app/public \
~/Downloads/ec2-public-filesYour EC2 security group must allow inbound SSH traffic on port 22 from your IP. The login username may be ubuntu, ec2-user, or another provider-defined user, depending on the selected machine image.
Set the Correct PEM Key Permissions
SSH can reject a private key if other users can read it. On macOS or Linux, run:
chmod 400 ~/keys/laravel-server.pemAlternatively:
chmod 600 ~/keys/laravel-server.pemNever store your PEM key inside a Laravel project, public directory, cloud-storage bucket, or Git repository.
Upload When the VPS User Cannot Write to /var/www
SCP cannot apply sudo directly to the remote destination. If ubuntu cannot write to /var/www/project, first upload to its home directory:
scp -r -i "~/keys/laravel-server.pem" \
~/Downloads/project-storage/app/public \
ubuntu@YOUR_SERVER_IP:/home/ubuntu/Connect to the server:
ssh -i "~/keys/laravel-server.pem" ubuntu@YOUR_SERVER_IPThen copy the contents with elevated permission:
sudo cp -a /home/ubuntu/public/. /var/www/project/storage/app/public/Confirm the destination before deleting any temporary files.
Fix Laravel Storage Permissions After Upload
The Apache or Nginx process must be able to access Laravel storage. On many Ubuntu installations, the web-server user is www-data:
sudo chown -R www-data:www-data /var/www/project/storage
sudo find /var/www/project/storage -type d -exec chmod 775 {} \;
sudo find /var/www/project/storage -type f -exec chmod 664 {} \;Avoid chmod -R 777, which grants unnecessary write access.
If the public storage link is missing, recreate it:
cd /var/www/project
php artisan storage:linkUse SCP with a Custom SSH Port
If SSH runs on port 2222, add uppercase -P:
scp -P 2222 -r -i "~/keys/laravel-server.pem" \
~/Downloads/project-images/. \
ubuntu@YOUR_SERVER_IP:/var/www/project/public/images/Lowercase -p has a different purpose: it preserves file timestamps and modes.
Common SCP Errors and Solutions
Permission denied (publickey)
The private key, login username, or key permissions may be incorrect. Test the connection with detailed output:
ssh -v -i "~/keys/laravel-server.pem" ubuntu@YOUR_SERVER_IPMake sure every command uses the same correctly spelled key filename.
No such file or directory
Check the local source:
ls -lah ~/Downloads/project-storage/app/publicCheck the remote directory:
ssh -i "~/keys/laravel-server.pem" ubuntu@YOUR_SERVER_IP \
"ls -lah /var/www/project/storage/app"Linux paths and filenames are case-sensitive.
Permission denied for the destination
The SSH user cannot write to the selected remote folder. Upload to /home/ubuntu/ first and move the files with sudo, or deliberately correct the destination ownership.
Connection timed out
Confirm that:
- The VPS or EC2 instance is running.
- The IP address or hostname is correct.
- Every IPv4 section is between
0and255. - Port
22, or the custom SSH port, is permitted by the firewall. - The AWS security group allows SSH from your current public IP.
Host key verification failed
This may happen after rebuilding a VPS or reusing an IP. Verify the server's new fingerprint with your provider before removing the outdated entry:
ssh-keygen -R YOUR_SERVER_IPOnly accept a replacement key after confirming it is legitimate.
SCP vs Rsync for Images and Large Asset Folders
SCP works well for straightforward uploads and downloads. For large image directories or repeated synchronization, rsync is more efficient because it transfers only changed files and provides progress information.
rsync -avz --progress \
-e "ssh -i ~/keys/laravel-server.pem" \
~/Downloads/project-images/ \
ubuntu@YOUR_SERVER_IP:/var/www/project/public/images/The trailing slash after project-images/ tells rsync to transfer the folder's contents.
Secure File Transfer Checklist
Before working with production files:
- Confirm the local and remote paths.
- Back up the destination or take a VPS snapshot.
- Check available disk space with
df -h. - Restrict SSH access to trusted IP addresses where possible.
- Test the command with one small file.
- Protect private keys and keep them out of Git.
- Avoid transferring
.envfiles and secrets unless required. - Verify file ownership and permissions after uploading.
- Check whether existing destination files could be overwritten.
Frequently Asked Questions
How do I download files from a VPS server to local?
Run SCP from your local terminal with the remote file first and local destination second:
scp -i "key.pem" user@SERVER:/remote/file ~/Downloads/How do I download images from an Ubuntu server?
Use scp -r to download an entire images directory:
scp -r -i "key.pem" user@SERVER:/var/www/project/public/images ~/Downloads/How do I upload files from local to a VPS?
Put the local file first and remote destination second:
scp -i "key.pem" ./local-file user@SERVER:/remote/path/Do I need to SSH into the server before using SCP?
No. SCP automatically creates an SSH connection. Run the command directly from your local terminal.
Is SCP secure for transferring website assets?
Yes. SCP encrypts the connection through SSH. You must still protect the private key and verify the remote server identity.
Can SCP resume an interrupted transfer?
SCP does not provide reliable transfer resumption. Use rsync over SSH for large folders or unstable connections.
Does SCP overwrite existing files?
Yes. A matching destination file can be overwritten without an interactive warning. Confirm your paths and back up important production data.
Conclusion
Whether you describe the task as downloading images and assets from a VPS to local or as an SCP file transfer using an SSH PEM key, the process follows four simple rules:
- For downloads, use
remote source → local destination. - For uploads, use
local source → remote destination. - Add
-rwhen copying directories. - Add
-iwhen authenticating with a private key.
SCP is a simple and secure solution for transferring files between a local computer and an Ubuntu VPS or AWS EC2 instance. For large asset folders and repeated synchronization, rsync can save time by transferring only changed files.
Suggested Internal Links
- How to Deploy a Laravel Application on Ubuntu VPS
- How to Set Laravel File and Folder Permissions
- How to Create the Laravel Storage Symbolic Link
- How to Configure an Apache Virtual Host for Laravel
- AWS EC2 vs Lightsail for Laravel Hosting