How to stream files from Raspberry Pi to a smartphone

Samba is designed to share files and folders that are defined in its configuration file. To share folders on the USB device, let's assume it has a bunch of folders:

$ ls /mnt/usb

documents downloads music videos

To share the downloads folder, open the /etc/samba/smb.conf file with nano, scroll down to the bottom and enter:

[Downloads]
comment = Place all your downloads here
Path = /mnt/usb/downloads
browseable = yes
writable = yes
read only = no
valid users = @users

This block of text will share the /mnt/usb/downloads directory with all users in the users group. Later, we'll mount this directory on both Linux and Windows computers. Users will then be able to configure their download managers to save the files directly to this folder on the USB device attached to the RPi, from any computer on the network.

You can also restrict access to some folders to certain users only:

[Documents]
comment = Important eyes-only PDF files
path = /mnt/usb/documents
browseable = no
writable = yes
read only = no
valid users = pi, bodhi

This will let only the users pi and bodhi mount and modify the contents of folders.

Transmission

Install the torrent server

Torrents are the preferred mediums for sharing open source content. Most Linux distros are distributed this way either via their own trackers or via linuxtracker.org.

There's no dearth of torrent clients for the Linux desktop. What sets Transmission apart from others is its easy-to-use web interface which resembles the desktop one. We'll install Transmission on Raspbian and then access it from any browser on any computer to add, monitor and control torrents.

To install Transmission, SSH into the RPi and type:

$ sudo apt-get install transmission-daemon

This will install and start the Transmission daemon. But before you can use it to download torrents, you need to configure it. Before making any changes to Transmission's configuration file, ensure that its daemon isn't running:

$ sudo service transmission-daemon stop

Also, before going any further, add the transmission user (debian-transmission), which is created automatically when the daemon is installed, to our group of users:

$ sudo usermod -a -G users debian-transmission

Now create a public share on the USB device, where we'll download the torrents. First, create the public share on the USB and assign the transmission user as its owner:

$ sudo mkdir /mnt/usb/public
$ sudo chown debian-tranmission /mnt/usb/public

Now add this share to Samba's configuration file:

[Public]
comment = Public share for torrents
browseable = yes
path = /mnt/usb/public
public = yes
writeable = yes
guest ok = yes

Share

Restart the smbd and nmbd services to make the share available to everyone. With the public share in place, it's time to configure the Transmission daemon. Its settings are defined in:

/etc/transmission-daemon/settings.json

Open the file in nano and first change the "rpc-whitelist-enabled": true parameter, to "rpc-whitelist-enabled": false to allow users to connect from all computers.

Next, specify the download directory with:

"download-dir": "/mnt/usb/public/downloads/Complete"

You can also separate incomplete files by keeping them in a different folder. First, enable the option by changing the "incomplete-dir-enabled": false parameter to "incomplete-dir-enabled": true and then specify the directory that'll house the incomplete downloads with "incomplete-dir": "/mnt/usb/public/downloads/Incomplete"

Mayank Sharma

With almost two decades of writing and reporting on Linux, Mayank Sharma would like everyone to think he’s TechRadar Pro’s expert on the topic. Of course, he’s just as interested in other computing topics, particularly cybersecurity, cloud, containers, and coding.