DEV Community

dpm_bush
dpm_bush

Posted on Originally published at sshflow.com

Using SCP on Windows: Install OpenSSH and Transfer Files

Need to copy a file from a Windows machine to a Linux server? Windows includes scp.exe as part of its OpenSSH Client optional feature, so you can transfer files from PowerShell, Windows Terminal, or Command Prompt without installing a separate SCP tool.

The main things to get right are whether OpenSSH is installed, which side of the command is remote, and how each operating system formats its paths.

Check that scp is available

In PowerShell, run:

Get-Command scp
Enter fullscreen mode Exit fullscreen mode

In Command Prompt, use:

where scp
Enter fullscreen mode Exit fullscreen mode

If Windows finds it, the result will usually point to C:\Windows\System32\OpenSSH\scp.exe. If neither command finds it, install OpenSSH Client from Settings → Apps → Optional features.

You can also install it from an elevated PowerShell window:

Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
Enter fullscreen mode Exit fullscreen mode

Open a new terminal after installation, then check again. OpenSSH Client also provides ssh, sftp, and ssh-keygen.

Upload and download files

The general form is:

scp [options] source destination
Enter fullscreen mode Exit fullscreen mode

A location written as user@host:path is remote. The order of source and destination determines the transfer direction.

To upload a Windows file to a Linux server:

scp C:\Users\dana\report.csv dana@server:/home/dana/
Enter fullscreen mode Exit fullscreen mode

To download a file from the server to Windows:

scp dana@server:/home/dana/report.csv C:\Users\dana\Downloads\
Enter fullscreen mode Exit fullscreen mode

Use Windows-style paths for the local side and forward slashes for paths on the Linux server. For more variations, including transfers in both directions, see this SCP file-transfer command reference.

Copy a directory

Add -r to copy a folder and its contents:

scp -r C:\Users\dana\reports\ dana@server:/home/dana/reports/
Enter fullscreen mode Exit fullscreen mode

Without -r, SCP does not recursively transfer a directory.

Use a custom port or private key

Use uppercase -P for a non-default SSH port:

scp -P 2222 C:\Users\dana\report.csv dana@server:/home/dana/
Enter fullscreen mode Exit fullscreen mode

Use -i to specify a private key:

scp -i C:\Users\dana\.ssh\id_ed25519 C:\Users\dana\report.csv dana@server:/home/dana/
Enter fullscreen mode Exit fullscreen mode

The port option is case-sensitive: lowercase -p has a different purpose in scp (preserving file modification times and permissions). Your private key is the file without the .pub suffix; the .pub file is the public key.

Windows paths, spaces, and multiple SCP programs

A local path containing spaces needs quotes so the shell passes it as one argument:

scp "C:\Monthly Reports\summary.csv" dana@server:/home/dana/
Enter fullscreen mode Exit fullscreen mode

There may also be more than one scp installed. Windows OpenSSH, Git for Windows, Cygwin, and WSL can each provide a different executable. Check which ones PowerShell can find with:

Get-Command scp -All
Enter fullscreen mode Exit fullscreen mode

In Command Prompt, use where scp.

Some non-Windows OpenSSH builds can interpret the colon in a path like C:\Users\dana\report.csv as the separator in a remote host:path location. If you see an unknown-host or missing-file error despite the file existing, change to its directory and use a relative path:

cd C:\Users\dana
scp report.csv dana@server:/home/dana/
Enter fullscreen mode Exit fullscreen mode

Diagnose failures by layer

When a transfer fails, check the simplest explanations first:

  • scp is not recognized: OpenSSH Client may be missing, or the terminal may not see the executable on PATH. Check the command location and open a new terminal after installing the feature.
  • No such file or directory: Confirm the local source exists and the remote destination directory exists. Check that local paths use Windows separators and remote paths use /.
  • Permission denied: Verify the remote username, destination write permissions, and authentication key. If using -i, confirm it points to the private key accepted by the server.
  • Connection refused: Check the server name, SSH port, whether the SSH service is running, and whether network or firewall rules allow the connection. Use -P if the server listens on a non-default port.

These checks separate a local path or executable problem from an SSH connection or remote permission problem.

SCP command versus SCP protocol

The scp command and the older SCP transfer protocol are not the same thing. Since OpenSSH 9.0, the command uses SFTP for file transfers by default; its familiar command syntax remains the same. If you need to connect to a server that supports only the legacy protocol, current clients can force it with -O:

scp -O C:\Users\dana\report.csv dana@server:/home/dana/
Enter fullscreen mode Exit fullscreen mode

For the practical differences between the command and the protocols involved, see this SCP and SFTP comparison.

I originally published a more detailed version of this guide on the SSHFlow blog.

I'm also building SSHFlow — an SSH client where every server gets its own workspace for terminals, SFTP, code, and databases.

Top comments (0)