copy files from linux to windows

How to Copy Files from Linux to Windows

Often system administrators need to transfer files across different platforms such as Linux and Windows. In this article, we will learn how to copy files from Linux to Windows.


How to Copy Files from Linux to Windows

Here are the steps to copy files from Linux to Windows. Basically, we have assumed that you have an FTP user ftpuser that allows you to connect from Linux to Windows. Using this user, we connect from Linux to Windows system, copy files from one system to another. For this purpose, we will create a shell script movefiles.sh on Linux system.

$ vi /home/ftpuser/movefiles.sh

Add the following lines to it.

#!/bin/bash


# Connect to windows ftp server
HOST=192.168.1.204
USER=ftpuser
PASS=test123


ftp -inv $HOST user $USER $PASS
binary
# Destination folder on remote network
cd /upload


# Source folder on local network
lcd /export/home/ftpuser/files
mput *.*
bye

EOF

Save and close the file. In the above code, we have stored FTP HOST, USERNAME and PASSWORD to connect to Windows system. Then we call ftp command to connect to the FTP server on Windows system. We use cd command to navigate to folder upload on remote system. We also navigate to /export/home/ftpusers/files folder on local system. Then we use mput command to copy all files from local folder to remote folder.

Make this file executable.

$ chmod +x /home/ftpuser/movefiles.sh

Run the file with the following command.

$ bash /home/ftpuser/movefiles.sh

You can also create a cronjob to run this script regularly. Run crontab command to open cronjobs.

$ crontab -e

Add the following line to run the script everyday at 10.a.m.

0 10 * * * /home/ftpuser/movefiles.sh >/dev/null 2>&1

Alternatively, you can also use commands like SCP to transfer files from Linux to Windows. But you need to have it installed on both systems with SCP user defined in Linux system, with access to Windows system.

Here is a simple command to copy files from local folder /home/ubuntu in Linux to remote folder /data on Windows.

$ scp /home/ubuntu/* username@host_ip:/data

On the other hand, if you want to copy files from remote Windows system to local Linux folder, just swap the source and destination in above command.

$ scp username@host_ip:/data/* /home/ubuntu

Copy file foobar.txt from local Linux folder to remote Windows folder /data.

$ scp /home/ubuntu/data.txt your_username@host_ip:/data

Copy the file “foobar.txt” from a remote Windows host to the local Linux folder.

$ scp your_username@host_ip:foobar.txt /home/ubuntu

You can always add these commands to a shell script or crontab to automate the process.

In this article, we have seen a couple of ways to copy files between Linux and Windows – using ftp & mput command, and using scp command. Of course, there are many other ways to do this. The key is to setup a Linux user to have access to Windows system. Once that is done, you can use any of the network file transfer commands to move your files.

Also read:

How to Copy Files from Linux to S3 bucket
How to Fix Permission Denied Error While Using Cat
How to Limit User Commands in Linux
How to Backup Website to Amazon S3
How to Check MD5 Checksum of Installed Packages

Leave a Reply

Your email address will not be published. Required fields are marked *