If you work with the RaspberryPi you will sooner or later encounter the problem of how to transfer files to the RasPi or copy them from the RasPi.
There are several ways to do this. A simple way is the transfer via FTP or SFTP.
If you communicate with your RasPi over the Internet, one of the two is certainly the first choice. But if you work in your home network it is much more comfortable to exchange files directly via Windows Explorer.
To make this possible you have to set up a share on the RasPi, which you can then mount as a network drive under Windows.
How to do that and what you have to pay attention to I have described in the following article.
Safety instructions
I know the following notes are always kind of annoying and seem unnecessary. Unfortunately, many people who knew "better" have lost eyes, fingers or other things due to carelessness or injured themselves. Data loss is almost negligible in comparison, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Because even the coolest project is not worth injury or other trouble.
https://www.nerdiy.de/sicherheitshinweise/
Affiliate links/advertising links
The links to online shops listed here are so-called affiliate links. If you click on such an affiliate link and make a purchase via this link, Nerdiy.de will receive a commission from the relevant online shop or provider. The price does not change for you. If you make your purchases via these links, you support Nerdiy.de in being able to offer other useful projects in the future. 🙂
Requirements
Helpful articles:
Before you start with this article you should have prepared the RaspberryPi so that it is accessible via the network and controllable via SSH.
The following three articles describe what needs to be done to prepare the RaspberryPi:
RaspberryPi – setup for nerdiys!
RaspberryPi – The first configuration!
RaspberryPi – Control the RaspberryPi via SSH
Basics of navigating in Windows Explorer
Required tool:
-no-
Required material:
In the following list you will find all the parts you need to implement this article.
Log in to the RaspberryPi via SSH
To start, you must first log in to the Rasp Pi with Putty via SSH. How to do this is in the article RaspberryPi - Control the RaspberryPi via SSH described.
Update package management
The package management in Linux is a "central place" through which various software packages can be installed. In order for this to work reliably, the lists and sources of the package management should be updated before each installation of new packages.
sudo apt-get update && sudo apt-get upgrade
Install the required programs or packages
So that you can share a folder you need of course a corresponding program which is also called package under Linux. The required package is called "Samba". You can install this "Samba" with the following command:
sudo apt-get install samba
Confirm these questions with a "j" and Enter. The installation will then continue.
Create the folder to share
In order to share access to a folder, you must first create a folder in your home directory.
This can be done with the following command:
mkdir ~/SharedFolder
In the screenshot you can see the home directory before and after the folder "ShareFolder" was created.
In the view of the home directory after creating the folder, the (red underlined) "ShareFolder" is then present.
Customize the Samba configuration file
Now we have to tell "Samba" where the folder to share is located and under what conditions we would like to share it. This can all be set in the Samba configuration file. This is called smb.conf. To edit it you have to execute the following command:
sudo nano /etc/samba/smb.conf
After you have opened the configuration file you maneuver the cursor with the arrow keys to the end of the file (i.e. all the way down). There you insert the following configuration text:
[Pi release] comment=Raspi Sharepath=/home/pi/release folder browseable=Yes writeable=Yes only guest=No create mask=0740 directory mask=0750 public=no
The easiest way to do this is to select the text, copy it, and then right-click to paste it into the appropriate location in the text file.
If you have chosen a different folder name or location for your shared folder you have to change the corresponding part under "path".
These configuration settings ensure that you have read and write permissions in the folder, that you can browse it and that only users who have previously logged in with a user name and password can access it.
To save the changes you have made, press CTRL+X on the keyboard and confirm the question whether you want to save before closing with a "y" (=yes) and ENTER.
This saved the changes you just made to the configuration file.
Samba will be restarted automatically and the new configuration will be applied.
Set up a user account
Since you have configured the share by specifying it in the configuration file so that only users with a username and password can access it, we now also need to create a username with a matching password.
This user name is the same as the Linux user currently in use. However, the password may be different from this one.
For example, to create the user "pi" you need to run the following command:
sudo smbpasswd -a pi
Set up network drive under Windows
Now you are done with the configuration under Linux.
Now you have to configure the shared folder in Windows as a network drive. You will then be able to access the shared folder as if it were a local drive (i.e. directly connected to your computer).
To configure this network drive, open the "Computer". This is the window in which inserted USB sticks, CD/DVD drives and hard disks are also displayed.
But you also have to tell Windows to use the user account that was created on the RaspberryPi.
Attention, this is going to get complicated for a moment:
You do this by prepending the user's domain to the user name, separated by a backslash (i.e. the slash on the sharp s key). The domain of the user in this case is your RasPi.
Long story short:
So you enter not only "pi" but also
"nameEuresRasPisprovidedUserName"
one.
In my example this would then be
"magicmirrorpi"
are.
In the password line, the password is entered normally.
After that click on "OK".
The window will close and a new window will open shortly afterwards.
This folder shows you now directly the content of the shared folder on the RasPi. All files that you copy to this drive will be copied directly to the RasPi.
So now you know how to share a folder on the RasPi and mount it as a network drive on a Windows system.
Have fun with the project
I hope everything worked as described for you. If not or you have questions or suggestions please let me know in the comments. I will then add this to the article if necessary.
Ideas for new projects are always welcome. 🙂
PS Many of these projects - especially the hardware projects - cost a lot of time and money. Of course I do this because I enjoy it, but if you think it's cool that I share the information with you, I would be happy about a small donation to the coffee fund. 🙂
Hi everyone,
I had put the question in the wrong post yesterday, sorry for that.
My problem is that, although I can integrate the external HDD (3.5” with its own power supply) into OMV and can also provide shares under Windows, no files or folders are displayed on the network drive. Message: “Folder is empty”.
Another external SSD (Nvme with adapter) shows up and I can access all files.
Actually, it can only be the HDD or the file format, or am I wrong here? The file format of the 3.5″ is NTFS, that of the small BTRFS.
What is striking, under Storage - Shared Folders the usual path is displayed under Device for the Nvme:
/dev/sda, with the large partition name “Movies” .
The absolute path, however, is displayed correctly. Does anyone have a tip for me what the problem could be. The tutorial is great and I followed it the same way, but without success.
Oh yes, Windows does not require a username and password when creating the network drive.
Thank you already.
greeting
Markus
Hi Markus,
so ad hoc I have no direct idea. It should actually also work with NTFS.
Can you copy the output of the “df -h” command here for me when the 3.5″ hard drive is connected.
This should list all attached drives including their mountpoints 🙂 .
Best regards
Fabian
Hey. Great instructions, thank you.
Unfortunately it says that my hard drive is write protected, even though I have assigned all rights.