← Back to Guides Homepage

Securely Transfer Files with SCP (Linux and Windows)

In this guide, you will learn how to securely transfer files and folders between Windows and Linux machines using the SCP (Secure Copy Protocol) command. SCP uses SSH for data transfer, providing the same authentication and security as the Secure Shell protocol.

Step 1: Prerequisites and Connectivity Check

Before transferring files, ensure that both your Windows and Linux machines have an OpenSSH Server installed and running. This is required to accept the incoming connection.

1. Test Connectivity

Use the PowerShell command Test-NetConnection (or the alias tnc) to verify that the target machine is reachable on port 22 (SSH).

tnc 192.168.1.5 -port 22

If the TcpTestSucceeded result is True, the SSH service is active and accessible.

Step 2: Transferring Files from Windows to Linux

We will initiate the transfer from the Windows machine PowerShell terminal.

1. Transfer a Single File

The basic syntax for transferring a file is: scp [source_file] [user]@[remote_host]:[destination_path].

scp file.iso linuxtest@192.168.1.5:/home/linuxtest/

You will be prompted for the Linux user's password. Once authenticated, the transfer will begin.

2. Transfer a Folder (Recursive)

To transfer a directory and all its contents, you must add the -r (recursive) flag.

scp -r folder_name linuxtest@192.168.1.5:/home/linuxtest/

Step 3: Transferring Files from Linux to Windows

You can also pull files from a Linux machine back to Windows, or push them from Linux. Here, we demonstrate pushing from the Linux terminal to Windows.

1. Important Path Formatting

When specifying the Windows destination path in SCP, you must use forward slashes (/) instead of the standard Windows backslashes (\), and the drive letter is often formatted as a path component.

scp -r folder_name wintest@192.168.1.10:C:/test/

Step 4: Troubleshooting with Verbose Mode

If a transfer fails or hangs, you can use the -v (verbose) flag to see detailed debug information about the connection, authentication, and transfer process.

scp -v file.iso wintest@192.168.1.10:C:/test/

This is extremely useful for diagnosing errors such as "No such file or directory" if you mistype the destination path.

← Back to Guides Homepage