Skip to content

Transfer Files Securely with SCP via PowerShell

To exchange files between Windows and Linux systems, SCP "Secure Copy" can be used, among other things.

SCP support is natively available starting with Windows 10 1803 and Windows Server 2019. This means SCP is useable onward this Versions without any need to install or configure expense. Which also means famous tools like Putty or WinSCP are not required.

SCP is not a PowerShell cmdlet, it's a commandline utility like ping, ipconfig etc.

Download

Copying files from remote machine to our local machine with using Powershell:

PowerShell
#copy one file
scp user@192.168.178.99:/home/user/config.conf "C:\Users\Cihan\Downloads\"
#copy folder recursively
scp -r user@192.168.178.99:/home/user/config "C:\Users\Cihan\Downloads\"
#copy one file and rename it
scp -r user@192.168.178.99:/home/user/config.conf "C:\Users\Cihan\Downloads\config_192_168_178_99.conf"

You will get a prompt for the remote password!

Upload

It's pretty much the same constellation:

PowerShell
#copy one file
scp "C:\Users\Cihan\Downloads\config.conf" user@192.168.178.99:/home/user/
#copy folder recursively
scp -r "C:\Users\Cihan\Downloads\config" user@192.168.178.99:/home/user/
#copy one file and rename it
scp "C:\Users\Cihan\Downloads\config.conf" user@192.168.178.99:/home/user/config_192_168_178_99.conf

You will get for uploads also a prompt for the remote password!

Explanation

Let's break it down:

SCP                           ➡️ Command
user                          ➡️ Remote user, which should have necessary permission
@192.168.178.99r              ➡️ IP/FQDN of the remote machine
:/home/user/config.conf       ➡️ Remote target file path
"C:\Users\Cihan\Downloads\"   ➡️ Local destination path

How SCP Works

  1. SCP connection to the remote host over SSH ➡️ so the file transfer is secured.
  2. Authentication over SSH using a Password or SSH Key
  3. Filetransfer over the encrypted SSH Channel
  4. SCP closes the connections

It's important to know, that SCP is not a protocol itself. It's a wrapper over SSH for file transfers. This means authentication, encryption and integrity check is handled by SSH.

🔴 SCP is using port tcp 22 by default, this can be changed if your using a custom port:

PowerShell
scp -P 2233 "C:\Users\Cihan\Downloads\config.conf" user@192.168.178.99:/home/user/ #-P stand for custom port

Cheers!