Copying a local file from Windows to a remote server using scp
Categories:
Transfer Files from Windows to Remote Server with SCP

Learn how to securely copy files from your local Windows machine to a remote Linux server using the SCP (Secure Copy Protocol) command-line utility.
Transferring files between your local Windows machine and a remote server is a common task for developers and system administrators. While various methods exist, SCP (Secure Copy Protocol) offers a secure and efficient way to move files over an SSH connection. This article will guide you through the process of using SCP from Windows to copy files to a remote server, covering prerequisites, basic commands, and common scenarios.
Prerequisites for Using SCP on Windows
Before you can use SCP, you need to ensure your Windows system is set up correctly. Modern versions of Windows (Windows 10 and 11) include an OpenSSH client by default, which provides the scp
command. If you are on an older version or scp
is not available, you might need to install an SSH client like PuTTY or enable the OpenSSH client feature.
scp
is available, open Command Prompt or PowerShell and type scp -V
. If it returns version information, you're ready to go. If not, you may need to enable the OpenSSH Client feature via 'Apps & Features' -> 'Optional features' -> 'Add an optional feature'.Understanding the SCP Command Syntax
The basic syntax for scp
is similar to the cp
(copy) command in Linux, but with added remote host and path specifications. When copying from a local machine to a remote server, you specify the local file path first, followed by the remote user, host, and destination path.
flowchart LR A[Local Windows Machine] --> B{"SCP Command"} B --> C[SSH Connection] C --> D[Remote Server] D --> E[Destination Directory] B --"Source File"--> A B --"User@Host:Path"--> D
Conceptual flow of an SCP file transfer from local to remote.
scp C:\path\to\local\file.txt username@remote_host:/path/to/remote/directory/
Basic SCP command to copy a file from Windows to a remote server.
Let's break down the components of the scp
command:
1. scp
The command itself, invoking the Secure Copy Protocol.
2. C:\path\to\local\file.txt
The full path to the file on your local Windows machine. Remember to use backslashes for Windows paths.
3. username
The username on the remote server that you will use to authenticate.
4. remote_host
The IP address or hostname of your remote server.
5. :/path/to/remote/directory/
The absolute path on the remote server where you want to place the copied file. The colon :
separates the host information from the remote path.
Practical Examples and Advanced Options
Beyond the basic file transfer, SCP offers several options for more complex scenarios, such as copying directories, specifying a different port, or using a specific SSH key.
username
on the remote_host
. If you're using SSH keys for authentication, you won't be prompted for a password.Copying a Directory Recursively
To copy an entire directory and its contents, use the -r
(recursive) option.
scp -r C:\path\to\local\folder\ username@remote_host:/path/to/remote/destination/
Copying an entire directory recursively.
Specifying a Different SSH Port
If your remote SSH server is listening on a port other than the default (22), use the -P
(note: uppercase P) option to specify the port.
scp -P 2222 C:\path\to\local\file.txt username@remote_host:/path/to/remote/directory/
Using SCP with a custom SSH port (e.g., 2222).
Using an SSH Key for Authentication
For enhanced security and convenience, it's recommended to use SSH keys instead of passwords. You can specify your private key file using the -i
option.
scp -i C:\Users\YourUser\.ssh\id_rsa C:\path\to\local\file.txt username@remote_host:/path/to/remote/directory/
Copying a file using a specific SSH private key for authentication.
id_rsa
in the example) has appropriate permissions (read-only for your user) to prevent unauthorized access. On Windows, this is typically handled by the SSH client, but it's good practice to be aware.