๐ก SCP ยท Secure Copy Protocol
Complete Guide to using SCP in Termux (Android) โ Every command explained in English.
Encrypted file transfer between your Android device (Termux) and remote servers.
1. Overview
scp (Secure Copy Protocol) is a command-line tool that allows you to securely transfer files and directories between your Android device (using Termux) and a remote server over SSH.
๐ Common use cases:
- Upload project files from Android to a Linux server.
- Download files from a server to Android.
- Backup files between devices.
2. Prerequisites & Installation
๐ง Step 1: Install OpenSSH in Termux
pkg update && pkg install openssh
๐ Explanation: Updates Termux package repositories and installs OpenSSH, which provides the
scp, ssh, and related commands.scp -V
๐ Explanation: Displays the installed SCP version to verify OpenSSH is correctly installed.
which scp
๐ Explanation: Shows the location of the scp binary file (e.g.,
/data/data/com.termux/files/usr/bin/scp).๐ Step 2: Verify SSH Access
ssh ubuntu@115.178.135.124
๐ Explanation: Attempts to log into the remote server as user
ubuntu at the given IP. If SSH works, SCP will work as well.โ
Note: SCP uses the same authentication and connection as SSH, so a successful SSH login is required.
3. Basic SCP Syntax
scp [options] source destination
๐ Structure:
source = file/folder to copy from, destination = target location. Options like -r, -P, etc., modify behavior.scp file.txt user@server:/path/
โฌ๏ธ Upload: Sends
file.txt from your local machine to /path/ on the remote server.scp user@server:/path/file.txt .
โฌ๏ธ Download: Retrieves
file.txt from the server and saves it in the current local directory (denoted by .).4. Uploading Files from Android to a Server
๐ Single file
scp /storage/emulated/0/Download/app.zip ubuntu@115.178.135.124:/home/ubuntu/
๐ฆ Explanation: Copies
app.zip from Android's Download folder to the Ubuntu user's home directory on the remote server.๐ Multiple files
scp file1.txt file2.txt file3.txt ubuntu@115.178.135.124:/home/ubuntu/
๐ Explanation: Sends three files at once to the server in a single command.
5. Uploading Directories (Recursive)
scp -r /storage/emulated/0/Download/regapicta ubuntu@115.178.135.124:/home/ubuntu/upload/
๐๏ธ Explanation: The
-r (recursive) flag uploads the entire regapicta folder and all its contents to /home/ubuntu/upload/ on the server.6. Downloading Files from a Server to Android
โฌ๏ธ Download to current directory
scp ubuntu@115.178.135.124:/home/ubuntu/app.zip .
๐ฅ Explanation: Downloads
app.zip from the server and stores it in Termux's current working directory.๐ Download to Android Download folder
scp ubuntu@115.178.135.124:/home/ubuntu/app.zip /storage/emulated/0/Download/
๐ฒ Explanation: The file is saved directly to Android's internal storage Download folder, making it accessible by other apps.
7. Downloading Directories (Recursive)
scp -r ubuntu@115.178.135.124:/home/ubuntu/project /storage/emulated/0/Download/
๐ Explanation: Downloads the entire
project folder from the server (including all subdirectories) to Android's Download folder.8. Using a Custom SSH Port
โ ๏ธ Important: scp uses uppercase -P (not lowercase -p).
scp -P 2222 app.zip ubuntu@115.178.135.124:/home/ubuntu/
๐ Explanation: Specifies port 2222 for the SSH connection (default is 22). Useful when the server listens on a non-standard port.
9. Using SSH Keys (Passwordless & Secure)
scp -i ~/.ssh/id_rsa app.zip ubuntu@115.178.135.124:/home/ubuntu/
๐ Explanation:
-i specifies a private key file (e.g., id_rsa) for authentication. More secure and avoids password prompts.scp -i ~/.ssh/id_rsa ubuntu@115.178.135.124:/home/ubuntu/app.zip .
๐ Explanation: Downloads a file from the server using key-based authentication. Ideal for automated scripts.
10. Viewing Transfer Progress (Verbose Mode)
scp -v app.zip ubuntu@115.178.135.124:/home/ubuntu/
๐ Explanation:
-v (verbose) prints detailed connection steps, SSH negotiation, and transfer progress โ excellent for debugging.scp -rv project ubuntu@115.178.135.124:/home/ubuntu/
๐ข Explanation: Combines
-r (recursive) with -v (verbose) for full logging of directory transfers.11. Compression During Transfer (Faster Transfers)
scp -rC project ubuntu@115.178.135.124:/home/ubuntu/
๐๏ธ Explanation: The
-C flag enables on-the-fly compression, reducing bandwidth usage and speeding up transfers of large folders.12. Accessing Android Storage in Termux
termux-setup-storage
๐ Explanation: One-time command to grant Termux access to Android's shared storage. Creates the symlink
/storage/emulated/0.cd /storage/emulated/0/Download
๐ Explanation: Navigates to the internal Download directory, a common location for files to upload.
| Location | Path |
|---|---|
| ๐ฑ Internal Storage | /storage/emulated/0 |
| ๐ฅ Download | /storage/emulated/0/Download |
| ๐ธ DCIM | /storage/emulated/0/DCIM |
| ๐ผ๏ธ Pictures | /storage/emulated/0/Pictures |
| ๐ Documents | /storage/emulated/0/Documents |
13. Real-World Examples
๐ฆ Upload Regapicta Project
scp -r /storage/emulated/0/Download/regapicta ubuntu@115.178.135.124:/home/ubuntu/upload/
๐ Explanation: Sends a development project folder from Android to a dedicated upload directory on the server.
๐ Upload requirements.txt
scp requirements.txt ubuntu@115.178.135.124:/home/ubuntu/upload/
๐ Explanation: Transfers a Python dependencies file to the server for application deployment.
๐ Upload Flask Application
scp -r flask_app ubuntu@115.178.135.124:/home/ubuntu/apps/
๐ Explanation: Uploads an entire Flask web app directory to the server's apps folder.
๐ฅ Download OCR Results
scp ubuntu@115.178.135.124:/home/ubuntu/output.json /storage/emulated/0/Download/
๐ Explanation: Fetches a JSON results file from the server and saves it to Android's Download folder.
14. Troubleshooting & Solutions
๐ Permission Denied
ssh ubuntu@115.178.135.124
๐ Explanation: Test SSH connectivity first. If SSH fails, SCP will also fail. Check username, keys, or server permissions.
๐ No Such File or Directory
ls -la /path/expected
๐ Explanation: Verify that the source or destination path exists. Use
ls to confirm file/folder presence.๐ซ Connection Refused
๐ก๏ธ Possible causes: SSH service not running on server, wrong port, or firewall blocking. On the server, check with
sudo systemctl status ssh.โฑ๏ธ Timeout
ping 115.178.135.124
๐ก Explanation: Check network connectivity. If ping fails, verify IP address, internet connection, or ISP restrictions.
15. Recommended Workflow (Android โ Ubuntu Server)
ssh ubuntu@115.178.135.124โ Test connectionscp -r regapicta ubuntu@115.178.135.124:/home/ubuntu/upload/โ Upload projectssh ubuntu@115.178.135.124โ Log into servercd /home/ubuntu/upload && ls -laโ Verify uploadcd regapicta && python -m venv venv && source venv/bin/activate && pip install -r requirements.txtโ Deploy application
โก Cheatsheet with Explanations
๐ค Upload file
Copy local file to remote server
scp file.txt user@server:/path/Copy local file to remote server
๐ Upload folder
Recursive copy of entire directory
scp -r folder user@server:/path/Recursive copy of entire directory
๐ฅ Download file
Save remote file to current local directory
scp user@server:/path/file.txt .Save remote file to current local directory
๐๏ธ Download folder
Download directory recursively
scp -r user@server:/path/folder .Download directory recursively
๐ Custom port
Specify SSH port (uppercase P)
scp -P 2222 file.txt user@server:/path/Specify SSH port (uppercase P)
๐ SSH key
Authenticate using private key
scp -i ~/.ssh/id_rsa file.txt user@server:/path/Authenticate using private key
๐๏ธ Compression
Enable compression for speed
scp -rC folder user@server:/path/Enable compression for speed
๐ Verbose debug
See detailed transfer logs
scp -v file.txt user@server:/path/See detailed transfer logs
๐ก Key takeaway: Every SCP command follows the pattern
source โ destination, with options for recursion, port changes, key authentication, or compression.
Comments