How To Use The `scp` Command to Copy a File From Remote to Local (and Vice Versa)
Learn how to **use the `scp` (Secure Copy Protocol) command** to securely transfer files **between your local machine and a remote server** in both directions. This beginner-friendly tutorial covers everything you need to copy files from **remote to local** and **local to remote** using simple command-line instructions.
`scp` is a command-line utility that uses SSH to **securely transfer files and directories** between systems. It’s a must-have tool for system administrators, developers, and anyone working with remote Linux or cloud servers.
What You’ll Learn in This Tutorial:
* Basic syntax and structure of the `scp` command
* How to copy files from remote to local
* How to copy files from local to remote
* How to copy entire directories using the `-r` flag
* How to change SSH port with `-P`
* Common use cases and troubleshooting tips
Prerequisites:
* Access to a remote machine with SSH enabled
* SSH credentials (username and IP or hostname)
* Terminal or Command Prompt with `scp` support (Windows, macOS, or Linux)
* For Windows 11 users: ensure OpenSSH Client is installed
SCP Command Syntax Overview:
```bash
scp [options] source destination
```
Copy a File from Remote to Local:
```bash
scp user@remote_ip:/remote/path/to/file.txt C:\Users\YourName\Downloads\
```
Copy a File from Local to Remote:
```bash
scp C:\Users\YourName\Documents\file.txt user@remote_ip:/home/user/
```
Copy a Directory from Local to Remote (Recursively):
```bash
scp -r C:\Users\YourName\Projects\ user@remote_ip:/home/user/
```
Copy a Directory from Remote to Local:
```bash
scp -r user@remote_ip:/home/user/logs/ C:\Users\YourName\Downloads\
```
Using a Custom SSH Port (e.g. 2222):
```bash
scp -P 2222 file.txt user@remote_ip:/home/user/
```
Tips:
* If the path contains spaces, wrap it in quotes
* Use `ssh` first to test your connection to the remote server
* For faster performance over SSH, add `-C` for compression
* You can also use `scp` with public/private SSH key authentication
Found this tutorial helpful? Like, share, and subscribe for more command-line tips, SSH tutorials, and Linux/Windows guides!
\#scp #scpCommand #Linux #Windows11 #SSH #SecureCopy #FileTransfer #RemoteAccess #TerminalCommands #SysAdmin #DevOps #CommandLineTips #RemoteToLocal #LocalToRemote #SecureFileTransfer #LinuxTools #WindowsTerminal #FileSync