Open In App

Transfer files and folders from Windows to Linux with WinSCP

Last Updated : 25 Sep, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Introduction

When using Linux machines, either as a Virtual Private Server or as a Virtual Machine on your local computer, one of the major problems that people encounter is to transfer their files from their host (main) machine to the Linux machine. This problem is generally resolved by a file transfer protocol client such as WinSCP and FileZilla. In this article, we shall learn how to transfer files and folders from Microsoft Windows to a Linux machine using the WinSCP software. WinSCP is a File Transfer Protocol client for Microsoft Windows. As said, it uses the FTP (File Transfer Protocol) and SFTP (Secure File Transfer Protocol) protocols to transfer files from a Windows machine to any other machine (Linux in this case).

Prerequisites

  • Windows machine with WinSCP installed.
  • Linux machine connected to the internet.

Transferring Files/Folders from Windows to Linux using WinSCP

Once you have the prerequisites, you can follow the following steps to transfer files and folders using WinSCP.

Step 1: Get the Public IP Address of your Linux Machine

The first thing we need is the IP address of the target Linux machine. To get this, open a terminal and then, type the curl command in the terminal:

curl ipinfo.io/ip

Here, we are sending an HTTP request to the ipinfo.io/ip website which is a utility that returns the Public IP address of the client machine. Thus, you will get an IPv4 address on your machine.

Getting the public IP Address

Getting the public IP Address

Step 2: Allowing FTP in the firewall

Now, if you are using a firewall, it is important to allow the FTP in your firewall otherwise the WinSCP will not be able to connect to your machine. Generally, Linux machines use the ufw firewall. To allow the FTP service, type the following command in your Linux terminal.

ufw allow ftp

On success, you will see a message like the following:

Allowing FTP in the firewall.

Allowing FTP in the firewall.

If you use some other firewall manager, use its corresponding commands to allow FTP.

Step 3: Connecting WinSCP to the Linux machine using the IP address

Now, open the WinSCP application on your windows machine. You will get a login prompt as follows:

WinSCP Login Window

WinSCP Login Window

Here, we will leave the File protocol to SFTP (Secure File Transfer Protocol), which means it will use port 22 for connecting to our Linux machine.

  • In the hostname, enter the Public IP address of the Linux machine found in step 1.
  • Then, enter the username which you want to connect using the machine and its password.
  • (Optional) You can also save the connection settings if you desire.

Once all the fields are filled, click on ‘Login‘ and you will be given a warning about whether you want to connect to the unknown target machine or not, like the following:

Warning for new connections.

Warning for new connections.

Allow it by clicking on the ‘yes‘ button and it will be added to your trusted sources, which means that the next time you connect to this same machine, you will not be given such a warning again. Now, you have an active connection between the Windows and the target Linux machine. The WinSCP will now show you files from both your host machine and the remote Linux machine as well like below:

WinSCP Window after successful connection

WinSCP Window after successful connection

On the left split window, we have the host machine and on the right, we have the remote Linux machine.

Step 4: Copying Files and Folders from host to remote machine.

Now, to transfer any files/folders all you have to do is copy them from the right window and paste it in the left window.

To copy, right-click on a file or folder and click on copy to clipboard. We are taking the dummy_tranfer.txt file and dummy_folder directory for copying in this example.

Copying file to Clipboard

Copying file to Clipboard

Then, in the remote machine, navigate to the folder you want to save the file/folder and right-click in it then, choose ‘Paste From Clipboard‘. In this example, we are copying the files into the /home/transfers/ directory in our Linux machine but, you are free to choose any directory However, be cautious of using the same later in the article as well.

Pasting the file/folder into the remote machine

Pasting the file/folder into the remote machine

The contents of the transfers folder will now look like:

Contents after successful transfer of files and folders.

Contents after successful transfer of files and folders.

We have now successfully learned how to transfer files and folders from Windows to a Linux machine using WinSCP.

Note: There is no difference between transferring a file and a folder. You copy and paste them both in the same manner as shown above.

Step 5: Verifying the copied files

Now, to verify whether we have the files in our Linux machine, open a terminal on your Linux machine and type the following ls command:

ls <path to the directory used in WinSCP transfer (Step 4)>

This will give us the contents of the /home/transfers directory in which we copied our files.

Verifying Transfer

Verifying Transfer

As we can see, we have got the folder and the file we copied to our Linux machine.

Step 6: Closing the connection

Once you are done transferring files/folders, always close the connection properly as an unclosed connection might lead to unexpected errors sometimes. To close the connection, navigate to the Tabs option in the toolbar then, choose Disconnect Session. Now, the session is successfully logged out.

Closing the connection to a remote server.

Closing the connection to a remote server.

Conclusion

In this article, we learned how to fetch the public IP address of a Linux machine and then, use that IP address to set up a login session in WinSCP using the SFTP protocol to transfer files and folders. Then, we ended the tutorial by learning how to close the connection. The WinSCP provides other protocols, such as FTP, SCP, etc. to transfer files. It depends on the user’s need to choose the appropriate one. However, in most general cases you would use the SFTP protocol, which is also recommended due to security reasons.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads