How to Transfer Files from Windows to Linux Using CMD

Introduction

While there are various methods available for file transfers from a Windows system to a Linux system, using the Command lines provides a straightforward and reliable approach. In this guide, we'll walk you through the step-by-step process, highlighting the necessary commands and techniques to seamlessly transfer your files from Windows to Linux.

Prerequisites

Verify Your Remote Linux Server is Ready
If you have ordered one from Database Mart, you will receive an email containing the information of your VPS, including server IP and login credentials. You can also obtain the information on the overview page in the control panel. Please refer to this guide on how to get server credentials if you need assistance.

Steps to Transfer Files from Windows to Linux Using Command Prompt

Step 1. Open the Command Prompt in Local Windows

Search cmd in the search bar, and double-click the Command Prompt to open it. Or press the Windows key + R, then type cmd or cmd.exe in the Run command box, and press Enter.

Open Command Prompt

Then, you should see the command prompt interface as below.

The Command Prompt interface
Step 2. Transfer Files between Local Windows and Remote Linux

Before the transfer, we will explain some terms used in the command. When using the command, you should replace these terms with the actual value.

filename.extension: it's the name of a file and file extension that's to be transferred. In this case, we may use mydata.txt and website.txt.
folderName: it's the name of a folder that's to be transferred. In this case, we may use the Website folder.
customPort: it's the custom port you use to connect to your remote Linux server.
localFilePath: it's the path on your local Windows PC.
username: it's the username used to log into the remote Linux server.
remoteServerAddress: it's the server IP of the remote Linux server.
remoteFilePath: it's the path on the remote Linux server. In this case, we use /home/administrator.

2.1 Transfer a File from Local to Remote Server

For demonstration purposes, we have created a file in the desktop>website named "mydata.txt". First, we need to go to the file's directory by inputting cd, followed by the file path on our local Windows. In this case, the file is located at desktop\website. Therefore, we enter the following command.

cd desktop/website

After that, you can see that we navigate to the folder where the file is located.

Navigate to the file path

Then, we use the following command to transfer the "mydata.text" from local Window to the remote Linux server.

scp filename.extension username@remoteServerAddress:remoteFilePath

After entering the command, you will be prompted for the password for connecting to the remote server. Input the password and hit the Enter button, the file will be transferred. In this case, we have transferred the local file mydata.txt (located at desktop/website) to the /home/administrator directory on the remote Linux server.

Transfer files from Local Windows to Remote Linux

2.2 Transfer a File from Remote Server to Local

You can run the following command to copy a file from the remote server to your local Windows PC.

scp username@remoteServerAddress:remoteFilePath/filename.extension localFilePath

In this case, we have transferred the mydata.txt (located at home/administrator on the remote server) to the desktop directory on the local server.

Transfer files from the remote server to the local server

2.3 Transfer Multiple Files from Local to Remote Server

The SCP command also allows you to transfer multiple files in a single command. Navigate to the file folder and run the following command.

scp localFilePath/filename1.extension localFilePath/filename2.extension username@remoteServerAddress:remoteFilePath

In this case, we have transferred two local files mydata.txt (located at desktop) and mywebsite.txt (located at desktop/website) to the /home/administrator directory on the remote Linux server.

Transfer multiple files from local to the remote server

2.4 Transfer a Folder from Local to Remote Server

Besides files, the SCP command also allows you to securely copy folders between the local and remote server. Use the following command to copy a folder from local to the remote server.

scp -r localFilePath/folderName username@remoteServerAddress:remoteFilePath

In this case, we have transferred the local Website folder, which contains two files mydata.txt and mywebsite.txt, to the /home/administrator directory on the remote Linux server.

Transfer a folder from local to the remote server

2.5 Transfer a File Faster

Adding the -c option after the scp command will compress the file while it’s being transferred. Once the file reaches its destination, it returns to its normal size.

scp -c localFilePath/filename.extension username@remoteServerAddress:remoteFilePath

In this case, we have transferred the local Website folder, which contains two files mydata.txt and mywebsite.txt, to the /home/administrator directory on the remote Linux server.

Transfer a folder from local to the remote server

2.6 Transfer a File Using a Custom Port

The scp command uses the 22 port by default. If you have changed to a custom port, please run the following command to transfer a file. Make sure to capitalize the P.

scp -P customPort localFilePath/filename.extension username@remoteServerAddress:remoteFilePath

In this case, we have transferred the local file mydata.txt to the /home/administrator directory on the remote Linux server using a custom port.

Transfer a file using a custom port from local to the remote server
Step 3. Verify the File has been Transferred

First, connect to your Linux server. If you need assistance in this area, please refer to how to connect to a Linux server remotely.

Log in to your Linux server

Then, Use a preferred editor to open the file. Here, we use the "Nano editor." In this example, the remoteFilePath is /home/administrator, and the filename.extention can be mydata.txt, mywebsite.txt, and myweb.txt.

nano remoteFilePath/filename.extention
Use the nano editor to open a file
Open the myweb file

We can also check if the folder has been copied to the remote server. Go to the /home/administrator directory and check if the Website folder is there.

cd /home/administrator
ll
Check if the Website folder has been transferred

Conclusion

In conclusion, transferring files from a local Windows machine to a remote Linux server using the command prompt (CMD) is a powerful and efficient method for managing data. By following the step-by-step guide outlined in this blog, you can establish a secure connection, utilize the SCP (Secure Copy Protocol) command, and successfully transfer files between these two platforms.

Other Methods to Transfer Files between Windows and Linux Server