Как скопировать файл с ubuntu на windows

We often copy files from one location to another on the same system. But sometimes you may need to copy files from Linux to Windows. In this article, we will learn how to copy files from Linux to Windows. You can also use these steps to copy folders across systems with different OS. We will also learn how to copy files from Windows to Linux.

Here are the steps to copy files from Ubuntu Linux to Windows.

1. Update System

First we need to update Linux system. Open terminal and run the following command for this purpose.

  

   


class=»wp-block-preformatted»>$ sudo apt update

2. Install SSH Server

Most Linux systems have SSH server pre-installed. If that is not the case with you, run the following command to install SSH server.

$ sudo apt install openssh-server

If you see any prompts during installation, just enter ‘y’ to proceed further.

After SSH server is installed, you can check its status with the following command.

$ sudo service ssh status

3. Install Samba

Samba is a Windows interoperability suite for Linux/Unix systems. It allows Linux/Unix systems to communicate with Windows systems easily. So we need to install this software before proceeding further. Run the following command for this purpose.

$ sudo apt install samba

You may be asked for sudo or account password to begin installation, enter it to proceed further. If you see any prompts during installation enter ‘y’ to proceed.

4. Create Samba User

Once you have installed Samba software on your system, you need to create a user for this software, using usermod command. You need to also enter the password. Here is the command to create a test user ‘test’ and set its password.

$ sudo useradd –M –N –g sambashare test
$ sudo smbpasswd –a test

5. Find IP Address of Windows

Next, you need to find the IP address of Windows system. Open command prompt on your Windows system and run ifconfig command to get its IP address.

$ ifconfig

The above command will show a lot of different information. The first adapter WLAN setting will display IP address.

5. Create Windows Folder

Next, within Local Disk folder (C:) you need to create a new folder ‘Share’. Next we need to update the privileges of this folder to allow remote access. To do this, right click the folder, and hover ‘Give Access to’. It will expand to show you a menu. Click ‘Specific people …’ as shown below.

How to copy files from linux to windows 1

It will open a window with a list of available users. Select the user ‘Everyone’ to give remote access. Select ‘Read/Write’ option from dropdown under Permission Level and click Share button.

Now this folder is shared and remote users can access it. Click Done to close the window.

6. Access Shared Folder from Ubuntu

Open File Explorer in Ubuntu, click ‘Other Locations’, check ‘Connect to Server’ at the bottom. Enter the Samba URL to your Windows system in text bar and click Connect button. Here is the format of Samba URL.

$ Smb://ip-address-of-windows/foldername

Here is a sample screenshot for your reference.

You will see a dialog box asking for your Samba username and password. Enter them and click Connect button.

You will see Share folder’s contents in File Explorer. You can right click them and click Copy to copy them.

7. Copy Files from Linux to Windows

If you want to copy files & folders from Linux to Windows you need to enable remote access to Linux folders. Create a new folder ‘Share’ in your Linux system. Right Click to see context menu and click ‘Properties’.

You will see a dialog box. Expand ‘Local Network Share’ and check ‘Share this folder’ option and ‘Allow others to create and delete’ option. Click Share button and close it.

You will see the share icon added to the folder’s icon.

To access this folder from Windows system, open run application in your Windows system. Enter the IP address of your Linux system as //ip-address and click Ok.

It will open the Share folder in Windows Network File Explorer.

In this article, we have learnt how to copy files from Windows to Linux and vice versa.

Also read:

How to Set Process Priority in Linux
How to Change Default MySQL Data Directory in Linux
How to Fix firewall-cmd command not found
How to Protect Hard and Soft Links in Linux
How to Run Shell Script on Another Server

The post How to Copy Files from Linux to Windows appeared first on Fedingo.

I recently installed Ubuntu on my VMWare workstation pro, and I realized that I need to transfer some files from my windows host machine to the Ubuntu Guest OS and vice versa.

There are many ways you could transfer files from linux to windows . Lets look at the simple and easiest ways to transfer files between windows and Ubuntu.

There are two methods that we are going to use.

  1. Transfer files to Windows using SMB in Ubuntu
  2. Transfer linux files using WinSCP

Though I am showing these methods in Ubuntu which is installed in VMware workstation under windows, this method of transferring files from windows to Ubuntu would work with any other Ubuntu hosts as well, not just on vmware workstation. Provided, there should be a network reachability between the hosts and firewall is not blocking the access.

1. Transfer files to Windows using SMB in Ubuntu

Step 1. First step is to make sure that you have connectivity between the Host machine and the Guest OS.

  • On my workstation pro I am using NAT interface for the Ubuntu VM
Ubuntu vmware workstation network configuration

  • And the Ubuntu Guest machine got the IP address 192.168.239.142/24 from the NAT interface.
  • Let’s ping the IP and make sure we are able to reach the Ubuntu VM from the Windows Host. And, Yes I can ping the IP address.
ping ubuntu vm from windows machine

Step 2. Share the folder in windows that you would like to transfer files to the Ubuntu machine.

  • I created a folder called Ubuntu files in my windows host.
  • Right click on the folder that you just created and click on Properties.
  • In the Properties window click on Sharing, and click on Advanced Sharing.
  • In the Advanced sharing window check the option which says share this folder, and click on Permissions.
  • In the permissions folder, you may control the permissions for the folder. I am giving full rights by checking all the options, Full control, Change and Read and click on OK.
  • You just shared a Folder on your windows machine, lets see how we are going to access the windows files from ubuntu.

Step 3. Access the windows files from Ubuntu.

  • Get the host windows machine IP address through CMD. As you can see my IP address is 192.168.0.19/24
transfer files from windows to ubuntu, check the ip of windows host

  • Open the file manager in Ubuntu and click on Other Locations.
  • Under connect to server type smb://192.168.0.19 and click on Connect.
enter smb address to transfer files from windows to ubuntu

  • As soon as you click on Connect the Ubuntu machine would prompt to enter the windows credentials.
enter the credentials to transfer files from windows to ubuntu

  • Once you are authenticated, you should be able to see the Ubuntu files folder that we had created under windows host machine.
we have successfully opened windows folder in ubuntu

  • Just double click on it and the folder would get auto mounted to your Ubuntu machine.
mount windows share folder in ubuntu

  • Now you can transfer files from windows to linux and linux to windows just like you would do on your regular PC.

2. Transfer linux files using WinSCP

If you ask someone who is an expert in linux world and ask them about How do I transfer files from a Linux box to windows, they would tell you to use WinSCP or FileZilla.

In this method we are going to use the tool called WinSCP.

What is WinSCP

WinSCP is a sofware that can let you transfer the files between different machine using a graphical user interface. It support verity of protocols such as SCP, FTP, SFTP and so on.

Step 1. Download the WinSCP software here on your windows machine, You may download the portable file or the installation setup file.

Step 2. In order for the SCP functions on the Ubuntu to work you would have to enable ssh in it, Follow the instruction here to enable the ssh on your Ubuntu machine.

Step 3. Open Winscp on your windows machine and in the login prompt

  • Select file protocol as SCP.
  • On the Host name field enter the IP address of your Ubuntu machine.
  • And enter the username and the password.
transfer files between linux and windows using winscp

  • Click on login and you will be able to see the windows files on the left side and the Ubuntu files on the right like below.
transfer files between linux and windows using winscp

In this tutorial we will learn how to use vsftpd on Linux to make Ubuntu machine run as ftp server and transfer files over wifi on local network.

On many occasion you need to copy and backup files locally from one computer to other. Using physical disk like flash drive or external hard drive is not always feasible due to many constraints such large file size, external drive availability.

  1. Setup
  2. Install VSFTP demon on Ubuntu
  3. Configure VSFTPD for uploads (Optional)
  4. Configure Ubuntu firewall for FTP
  5. Configure Windows Firewall
  6. Initiate FTP session using Windows command line
  7. Initiate FTP connection using ftp client on windows
  8. Understanding Security Aspects — Firewall and Services

Setup

We can take advantage of machines being on same network to achieve file transfer.

To follow this guide you should have access to following

  • Ubuntu Machine
  • Windows Machine
  • Both machines connected over same network using ethernet or wifi

How to install VFTP on Ubuntu

Open Terminal to get and install vsftp demon from official ubuntu repository.

sudo apt-get install vsftpd

Above command will install vsftp demon which means it will always be running in background upon machine startup using init.

Use following commands to check vsftp service

sudo service vsftpd status

If service is running then above command will output status of service with all spawned vsftp process ids.

Alternatively you can also check vsftp process with grep

ps -ef | grep vsftp

How to configure VSFTP for Uploads

This step is optional but if you want to allow uploads from remote machine to your ubuntu server then follow below configuration.

After installation vsftp will create configuration file at path /etc/vsftpd.conf. This file should be owned by root and should have default vsftp configuration. By default VSFTP will not allow ftp uploads; to enable it uncomment line write_enable=YES

# Uncomment this to enable any form of FTP write command.
write_enable=YES

Note that /etc/vsftpd.conf would be owned by root, to make any changes in configuration do. sudo vim /etc/vsftpd.conf or sudo gedit /etc/vsftpd.conf

Restart vsftpd demon once configuration is completed.

sudo service vsftpd restart

Check status after restart.

sudo service vsftpd status

How to configure Ubuntu firewall for FTP

By default ubuntu shall be running firewall known as uncomplicated firewall (ufw). Default firewall rules will not allow any outside connection.

To open ftp port on this firewall use following commands.

Check firewall status using

sudo ufw status

Firewall should be active and running. If it’s not active then enable the same using following command to make your machine secure.

You can keep it disable if you have such requirement, however it’s recommended to keep it on. sudo ufw enable

To open ftp port 21 use following command

sudo ufw allow ftp or sudo ufw allow 21

This will add firewall rule to accept ftp connections from other machine on network. After adding ftp rule you should have following entries in your firewall. sudo ufw status


Status: active
To                         Action      From
--                         ------      ----
21/tcp                     ALLOW       Anywhere                  
21/tcp (v6)                ALLOW       Anywhere (v6)     

Configure Windows Firewall

Firewall should permit you to initiate ftp session from windows machine. Search for Windows Firewall in start menu to open firewall configuration window.

Since we are going to use one time ftp we will disable firewall and reenable it once ftp is done. Depending upon which network you are connected to Home or Public you can disable firewall like below.

Screenshot : Disable Windows Firewall

Note that disabling complete firewall is not recommended. If you are going to use ftp server regularly from windows machine then please create firewall rules under Windows Firewall with Advanced Security on Port 21

Initiate FTP session using Windows command line

Once we are done with required configurations we can initiate first ftp connection from windows command line. First get IP address of machine hosting FTP server using command ifconfig on ubuntu machine. Use eth0 inet address if you are connected with ethernet cable. For wireless connection use inet address of wlan0 interface. My ubuntu machine have following local IP 192.168.2.102.

ifconfig


eth0      Link encap:Ethernet  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

wlan0     Link encap:Ethernet  
          inet addr:192.168.2.102  Bcast:192.168.2.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:24006 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8312 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:12996852 (12.9 MB)  TX bytes:1224374 (1.2 MB)

To initiate connection open command prompt on windows and use following command. ftp 192.168.2.102

It will ask for username and password. Username will be same name as the ubuntu user (techmonger in my case) and password will the ubuntu’s system password of user.

windows cmd ftp login vsftpd ubuntu

To get file from ubuntu ftp server, navigate to directory and use get command like below.

ftp>get filename

To upload file from windows machine to ftp server, put command like below.

ftp>put filename

To terminate ftp session use bye.

ftp>bye

Initiate FTP connection usign ftp client on windows

By now you would agree that doing ftp from windows command prompt is bit tedious. We can use ftp client such as winscp or filezilla to get GUI for ftp operations.

Use hostname as IP address of ftp server (192.168.2.102 in my case) and same credentials as those of ubuntu user.

Like below you can initiate connection from filezilla. You can use drag and drop to download and upload files from windows machine.

windows filezilla ubuntu vsftp

FTP Security Aspects — Firewall and Services

All ftp connections will be initiated in plain text. You should only use above method if you are in local network and have complete control over network. For encrypted connections use sftp or ftps.

  • Remove firewall rule from ubuntu once ftp requirement is over.

  • sudo ufw deny ftp or sudo ufw deny 21

  • Enable Winows firewall once ftp requirement is over.

  • Stop vsftp demon if ftp is no longer needed to save system resources. It will also make your system less vulnerable.

    sudo service vsftpd stop

Conclusion : You can make your ubuntu machine to run as ftp server and can transfer files locally. You do not need SMB (server message block) for file transfer between linux machine and windows machine over network.

Copying files in Windows or Linux is simple enough. Copying files between them, though, not so much. The classic copy-paste with a USB stick method does work, but it’s not very efficient.

Instead, you can transfer files using protocols like SMB and SSH and using FTP applications such as FileZilla. We’ve listed step-by-step instructions for these and more methods in the sections below.

Ways to Transfer Files between Linux and Windows

Before you start, do keep in mind that, unlike Windows, Linux is case-sensitive. When entering the commands or file paths, users often forget this and can’t figure out why the file transfer doesn’t work despite following the steps correctly.

With that said, here are the various ways to transfer files between Linux and Windows.

Transfer Files Using SMB

The Server Message Block (SMB) protocol is a client-server communication protocol built into most Linux distributions. Here are the steps to transfer files using SMB:

  1. On your Windows system, locate the folder you’re trying to share.
  2. Right-click the folder and select Give access to > Specific People.
    give-access-to-specific-people

  3. Click on Share and press Done on the next screen.
    choose-people-to-share-with

  4. Next, press Win + R, type cmd, and press Enter.
  5. Type ipconfig and press Enter. Note the IPv4 address of the first adapter on the list.
    ipconfig-ipv4-address

  6. On the Linux system, launch the File Browser and click on + Other Locations.
  7. In the Connect to Server field, enter the IP from Step 5 in the following format:
    smb://IP
    ubuntu-network-locations-smb-ip

  8. At the authentication prompt, enter your Windows account credentials and press Connect. You can now use this folder to transfer files between Linux and Windows.

Transfer Files Using SSH

Secure Shell Protocol (SSH) is a cryptographic network protocol commonly used for remote login. With an SSH client such as PuTTY, you can transfer files between Linux and Windows via the command line. Here are the steps to do so:

  1. On the Windows system, download and install PuTTY if you haven’t already.
  2. On the Linux system, press CTRL + Alt + T to launch the Terminal.
  3. Install and enable SSH with the following commands on Debian-based Linux systems such as Ubuntu:
    sudo apt install ssh
    sudo systemctl enable ssh --now
  4. On RedHat, CentOS, Fedora, and other systems, use these commands instead:
    sudo apt install OpenSSH
    sudo systemctl enable sshd --now
  5. In case you’re getting blocked by the firewall, use the following command:
    sudo ufw allow 22/tcp
  6. Enter ip addr and note the IP Address.
    ip-addr

  7. On the Windows system, open Command Prompt and use the commands listed below as appropriate.
  8. The following command is to copy a single file. The example shows the file named doc.txt being copied from a remote Linux system to the D drive on the Windows system.
    pscp user@host:remote_path/file_name host_path\file_name
    ssh-pscp-file-transfer-syntax

  9. To copy all files in a folder:
    pscp user@host:remote_path/* host_path\ 
    eg: pscp anup@192.168.10.65:/home/anup/Desktop/naya/* D:\testfolder\ 
  10. To copy all files & folders in a folder:
    pscp -r user@host:remote_path/ host_path\
    eg: pscp -r anup@192.168.10.65:/home/anup/Desktop/naya D:\testfolder\

Transfer Files Using SFTP

You can also use a third-party tool such as FileZilla to transfer files using SFTP (SSH File Transfer Protocol). Here are the steps to do so:

  1. On the Linux system, follow Steps 1 – 6 from the section above to set up SSH.
  2. On the Windows system, launch FileZilla and select File > Site Manager > New Site.
  3. In the Protocol field, select SFTP – SSH File Transfer Protocol.
    filezilla-sftp-ssh

  4. In the Host field, enter the Linux IP Address from Step 6 of the section above.
  5. Fill in the login credentials of your Linux system and press Connect.
  6. If prompted, enable the Always trust this host option and press OK.
  7. Now that the connection is established, you can transfer files between Windows and Linux by dragging and dropping or right-clicking the file and selecting Upload/Download.
    upload-filezilla

How to Transfer File from Linux to Windows VM?

You can easily transfer files from Linux to a Windows VM using a USB Stick. Of course, that’s just one easy method. We have an article that details multiple ways to transfer the files for your further reading.

Установим SMBCLIENT

sudo apt install smbclient

Отобразить все сетевые шары

smbtree -N

Для входа в интерактивный режим запустите команду вида:

 sudo smbclient //ИМЯ-КОМПЬЮТЕРА/Папка -N 

Например, я хочу подключиться к компьютеру test-pc и выполнить действия с файлами в сетевой папке Share, тогда моя команда следующая:

 sudo smbclient //test-pc/Share -N 

Если вы хотите, чтобы при подключении была изменена текущая рабочая директория в сетевой папке, то есть чтобы была открыта другая папка, то используйте опцию -D. К примеру, я хочу подключиться к папке NewFolder, тогда команда следующая:

sudo smbclient //test-pc/Share -N -D NewFolder

К примеру, на компьютере test-pc имеется сетевая папка ShareTest, права на просмотр которой есть у пользователя TestUser. Для просмотра шары, защищённой паролем, нужно использовать команду вида:

sudo smbclient //ИМЯ-КОМПЬЮТЕРА/Папка -U ИМЯ-ПОЛЬЗОВАТЕЛЯ

В моём случае это команда:

sudo smbclient //test-pc/ShareTest -U TestUser

Скачать файлы с общей папки:

get <ИМЯ_УДАЛЁННОГО_ФАЙЛА> [ЛОКАЛЬНОЕ_ИМЯ]

Для повторного скачивания файла:

reget <ИМЯ_УДАЛЁННОГО_ФАЙЛА> [ЛОКАЛЬНОЕ_ИМЯ]

Для скачивания всех файлов, чьём имя совпадает с шаблоном:

mget ШАБЛОН_ИМЕНИ

Например, чтобы скачать все файлы с файловым расширением .exe нужно запустить такую команду:

mget "*.exe"

Для каждого файла, совпавшего с шаблоном, будет выполнен запрос на скачивание. Если вы действительно хотите его скачать, то нажмите клавишу «y»

put <ЛОКАЛЬНОЕ_ИМЯ> [ИМЯ_УДАЛЁННОГО_ФАЙЛА]

Следующая команда скопирует локальный файл в шару:

print ИМЯ_ФАЙЛА

Повторная закачка файла:

reput <ЛОКАЛЬНОЕ_ИМЯ> [ИМЯ_УДАЛЁННОГО_ФАЙЛА]

Для закачки всех файлов, чьём имя совпадает с шаблоном:

mput ШАБЛОН_ИМЕНИ

К примеру, чтобы закачать в шару все файлы (из локальной текущей рабочей директории), которые имеют расширение *.cap, нужно запустить команду:

mput "*.cap"

Для каждого файла, совпавшего с шаблоном, будет выполнен запрос подтверждения, если вы действительно хотите его закачать, то нажмите клавишу «y»

Понравилась статья? Поделить с друзьями:
0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии
  • Windows 10 lite последняя версия
  • Как включить службу гаджетов windows 7
  • Как перезапустить windows search
  • Добавить пользователя в windows сервер 2019
  • Скриншот монитора windows 10