How To Copy File From Windows To Linux Using Command Line : SCP Command File Transfer

Using the command line, you can securely transfer a file from a Windows system to a remote Linux server with a single command. This guide covers exactly how to copy file from windows to linux using command line, step by step, with no extra fluff. Whether you are a developer, sysadmin, or just learning, you will find clear instructions here.

Many people think copying files between operating systems is complicated, but it is actually quite simple. You only need a few tools that are often already installed on Windows. The most common method uses SCP (Secure Copy Protocol) or SFTP (SSH File Transfer Protocol). Both are secure and fast.

In this article, we will focus on practical steps. You will learn how to set up your Windows command prompt, connect to a Linux server, and transfer files safely. We also cover common errors and how to fix them. Let’s get started.

Prerequisites For Copying Files From Windows To Linux

Before you begin, you need a few things ready. First, make sure you have a Linux server or machine that you can access remotely. You need the IP address or hostname of that Linux system. Second, you need a username and password (or SSH key) for that Linux machine.

On your Windows computer, you need a command-line tool. Windows 10 and 11 come with OpenSSH Client built-in. If you have an older Windows version, you may need to install it manually. Alternatively, you can use third-party tools like PuTTY or Git Bash, but we focus on native Windows tools here.

Finally, ensure your Windows machine can reach the Linux server over the network. If they are on the same local network, this should work. For remote servers over the internet, you need proper network access and firewall rules.

Check If OpenSSH Client Is Installed On Windows

Open PowerShell or Command Prompt as administrator. Type the following command and press Enter:

ssh

If you see a list of options, OpenSSH is installed. If you get an error like “not recognized,” you need to install it. Go to Settings > Apps > Optional Features > Add a feature. Search for “OpenSSH Client” and install it. Restart your terminal after installation.

Verify SSH Access To The Linux Server

Before copying files, test that you can SSH into the Linux server. In your Windows terminal, type:

ssh username@linux-server-ip

Replace “username” with your Linux user and “linux-server-ip” with the actual IP address. If prompted, accept the host key. Enter your password when asked. If you see the Linux command prompt, SSH works fine. Type exit to return to Windows.

How To Copy File From Windows To Linux Using Command Line

Now we get to the main topic. The most straightforward way to copy a file is using the scp command. SCP stands for Secure Copy Protocol. It uses SSH for encryption and authentication. Here is the basic syntax:

scp [options] source_file username@destination_ip:/path/to/destination/

For example, to copy a file named “report.txt” from your Windows desktop to a Linux server at 192.168.1.100, into the /home/user/documents/ folder, you would run:

scp C:\Users\YourName\Desktop\report.txt user@192.168.1.100:/home/user/documents/

Press Enter. You will be prompted for the Linux user’s password. After entering it, the file transfers. You will see a progress bar and a confirmation message when done.

Step-By-Step Example With A Real File

Let us walk through a complete example. Suppose you have a file named “data.csv” on your Windows desktop. You want to copy it to a Linux server with IP 10.0.0.5, user “admin”, into the /tmp/ directory.

  1. Open Command Prompt or PowerShell on Windows.
  2. Navigate to the folder containing the file, or use the full path. For simplicity, use the full path.
  3. Type: scp C:\Users\YourName\Desktop\data.csv admin@10.0.0.5:/tmp/
  4. Press Enter. If this is the first time connecting, you will see a host key warning. Type “yes” and press Enter.
  5. Enter the password for the “admin” user on the Linux server.
  6. Wait for the transfer to complete. You will see a progress indicator like “data.csv 100% 12KB 12.0KB/s 00:00”.
  7. The file is now on the Linux server in /tmp/.

That is all there is to it. The command is simple and effective. You can also copy multiple files at once by listing them or using wildcards.

Copying Multiple Files Or Directories

To copy multiple files, list them one after another before the destination. For example:

scp file1.txt file2.txt user@server:/path/

To copy an entire directory, use the -r (recursive) option:

scp -r C:\MyFolder user@server:/home/user/

This copies the folder and all its contents. The recursive flag is essential for directories; without it, SCP will fail.

Using SFTP For Interactive File Transfers

Another powerful method is SFTP (SSH File Transfer Protocol). It provides an interactive session where you can navigate, list, and transfer files. This is useful if you are unsure of the exact path or want to browse the remote server.

To start an SFTP session, type:

sftp username@linux-server-ip

Enter your password. You will see an sftp> prompt. Here are common commands:

  • ls – List files on the remote server.
  • lls – List files on your local Windows machine.
  • cd – Change directory on the remote server.
  • lcd – Change directory locally.
  • put filename – Upload a file from Windows to Linux.
  • get filename – Download a file from Linux to Windows.
  • exit or bye – Close the session.

For example, to upload “backup.zip” from your Windows Downloads folder to the Linux home directory:

  1. Start SFTP: sftp user@server
  2. Navigate locally: lcd C:\Users\YourName\Downloads
  3. Navigate remotely: cd /home/user/
  4. Upload: put backup.zip

SFTP is great for interactive use. It also supports wildcards, so you can do put *.txt to upload all text files.

Using PSCP From PuTTY Suite

If you prefer using PuTTY, it comes with a tool called PSCP. This works exactly like SCP but is a separate executable. Download PuTTY from the official site and install it. PSCP is included.

Open Command Prompt and navigate to the PuTTY installation folder (usually C:\Program Files\PuTTY). Or add it to your PATH. Then use:

pscp C:\file.txt user@server:/path/

It works identically to SCP. The advantage is that PSCP can use PuTTY’s saved sessions, which is handy if you have complex SSH configurations.

Common Errors And Troubleshooting

Even with simple commands, things can go wrong. Here are frequent issues and how to fix them.

Permission Denied (Publickey)

This error means SSH key authentication failed. You either need to use a password or set up an SSH key. If you are using a password, make sure you typed it correctly. If using keys, ensure the public key is on the Linux server in ~/.ssh/authorized_keys.

Connection Timed Out

This usually indicates a network issue. Check that the Linux server is reachable. Ping the IP address from Windows: ping 192.168.1.100. If ping fails, check firewall rules on both sides. Also ensure the SSH service is running on Linux: sudo systemctl status ssh.

No Such File Or Directory

Double-check your paths. On Windows, use backslashes or forward slashes (both work in most cases). On Linux, paths are case-sensitive. Also verify the destination directory exists on the Linux server. You can create it with mkdir -p /path/to/dir.

Host Key Verification Failed

This happens when the remote server’s host key changes. If you trust the server, remove the old key from your known_hosts file. On Windows, this file is at C:\Users\YourName\.ssh\known_hosts. Delete the line with that server’s IP or hostname. Then try again.

Automating File Transfers With SSH Keys

Typing passwords every time is tedious. You can set up SSH key-based authentication for passwordless transfers. This is also more secure.

First, generate an SSH key pair on Windows. Open PowerShell and run:

ssh-keygen -t rsa -b 4096

Press Enter to accept the default location (C:\Users\YourName\.ssh\id_rsa). You can set a passphrase for extra security, or leave it blank for automation. The public key will be id_rsa.pub.

Next, copy the public key to your Linux server. Use this command:

type C:\Users\YourName\.ssh\id_rsa.pub | ssh user@server "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

Enter your password one last time. After that, SCP and SFTP commands will work without a password prompt.

Copying Files From Linux To Windows (Reverse Direction)

While this article focuses on Windows to Linux, the reverse is equally simple. Just swap the source and destination in the SCP command:

scp user@server:/path/to/file C:\destination\

For example, to download “log.txt” from Linux to your Windows desktop:

scp user@192.168.1.100:/var/log/log.txt C:\Users\YourName\Desktop\

SFTP also works: use get filename to download.

Using Rsync On Windows For Advanced Transfers

Rsync is a powerful tool for syncing files. It is native to Linux but can be used on Windows via WSL (Windows Subsystem for Linux) or third-party ports. If you have WSL installed, you can run rsync from the Linux terminal inside Windows.

Basic rsync command to copy a file:

rsync -avz /mnt/c/Users/YourName/Desktop/file.txt user@server:/path/

Rsync is great for large transfers because it only copies differences. It also preserves permissions and timestamps.

Security Considerations

Always use encrypted protocols like SCP or SFTP. Never use plain FTP or Telnet, as they send passwords in cleartext. Also, avoid using root accounts for transfers; create a regular user with sudo privileges if needed.

If you are transferring sensitive data, consider using SSH keys with a passphrase. Also, verify the integrity of transferred files using checksums. On Linux, you can run md5sum filename after transfer to compare with the original.

Frequently Asked Questions

Can I Copy A File From Windows To Linux Without Installing Any Software?

Yes, if you have Windows 10 or 11 with OpenSSH Client enabled. SCP and SFTP are built-in. For older Windows, you may need to install OpenSSH or use PuTTY’s PSCP.

What Is The Difference Between SCP And SFTP?

Both use SSH for security. SCP is simpler and faster for one-time transfers. SFTP is interactive and supports more features like resuming interrupted transfers and directory listing.

How Do I Copy A File With Spaces In Its Name?

Enclose the filename in quotes. For example: scp "C:\My Files\report.txt" user@server:/path/. On Linux, also use quotes or escape spaces with backslashes.

Why Is My SCP Command Very Slow?

Slow transfers can be due to network latency, large file size, or encryption overhead. Try using compression with the -C flag: scp -C file user@server:/path/. Also check your network speed.

Can I Copy A File From Windows To Linux Using PowerShell?

Yes, PowerShell works the same as Command Prompt for SCP and SFTP commands. You can also use PowerShell remoting if both systems are configured, but SCP is simpler.

Now you have a complete guide on how to copy file from windows to linux using command line. The methods described are reliable, secure, and easy to use. Practice with small files first, then move to larger transfers. With SSH keys set up, you can automate backups and syncs effortlessly. Remember to always check your paths and permissions. Happy file transferring!