Getting older, not necessarily wiser!
In this post we will talk about moving files across the network using the Secure Copy (scp) protocol. The server we built in the last post already has this capability, and it is generally quicker than using a USB stick.
If you recall from the last post, when we created our UPnP server, we installed openssh so we could log in remotely (headless operation without keyboard, or monitor). The openssh package is a suit of protocols, one of them being the scp protocol.
We do not need to install anything new, at least on the server. We just need to learn how to use the scp protocol to transfer files.
If you have not been following this series of posts, then you can check availability on your server by typing scp from a command prompt. If it is available you will get a small usage blurb. If not, you should get a “program not found” message.
If it is not there you can install openssh through your package manager. On Debian based systems that use the apt package manager, the command would look like this.
apt install openssh-server
And yes, I left the sudo off. You need to have sudo privileges of be root to install program packages on Linux systems.
On Arch based systems the command would look like this. Note there are differences in how open ssh is packaged between various package managers.
pacman -S openssh
Once installed you can check if it is running with the following command.
systemctl status ssh
This is similar to what we did with the UPnP server in the last post (you should really read it).
You will need a scp client program on your main computer. If you do not have one, then you can install the openssh-client package to get one.
The scp command has a similar structure to the cp command. Unlike cp, the scp command allows the addition of users and hosts to the source and destination file paths.
scp [options] [user@host:source] [user@host:destination]
If you are copying files from your local machine, you do not need the host information. However you will need host information for your server. In our case this includes a user name, a password, and an ip address. From our last post, the IP address is 192.168.10.10. The username is minidlna, But we do not have a password for this user.
I had some issues setting up a password for the minidlna user, and getting the user to behave correctly. Which I am going to have to work though. My workaround, at this point, is to reinstall the system and create the minidlna user before installing the minidlna package.
useradd -m minidlna passwd minidlna
The above will create the user, the home folder, and assign a password. Don’t forget to create your actual media folders.
If you install the minidlna package after this, you will not have any problems using the scp program.
Lets assume our media file is called music.mp3. And we want to send it to the music sub folder in the home folder of the miniDLNA user, now that we have a password
Open a command prompt and cd to the directory containing the media file you want to transfer (unless you are in the directory, you will need to enter full path information, and that can be a lot of typing).
Now we can execute the scp command to send our file to the server across the network.
scp music.mp3 miniDLNA@192.168.10.10:/home/minidlna/music
You will be prompted for the miniDLNA password before the copy will then take place.
If we wanted, we could have changed the file name, just like with the cp command. But in this case we did not provide a new file name.
You can also use wild cards to transfer multiple files. For example we could have used “*.mp3” to transfer all MP3 files in the directory.
In this post we covered the basics of using the scp program to move files across the LAN to our minidlna server. This is probably the easiest, if not particularly intuitive, way to get media files on your server.
In the next post we will talk about using FTP.
Part 3 Using Secure Copy Protocol (scp) on a Server