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.
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:
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:
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:
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:
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.
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.
The contents of the transfers folder will now look like:
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.
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.
Contact Us