10 years ago
This tutorial is inspired by the Motion tutorial written by RayWoods. It's aim is to go a step further with the security aspect. The reasoning is that storing pictures of someone breaking in to your home on a local hard drive will only provide them with a nice souvenier of the theft. On a less cynical note, you could also use this to automatically publish webcam shots to a website ^_^
This tutorial will be using the command line and some basic scripting, as well as a tool called incron.
Pretty much anybody.
That you have a web domain with some disk space and FTP access, an always on broadband or cable connection and finally, that you have a terminal open!
We are going to be using the command line FTP client as this is a scripted solution. Additionally, the script needs to automatically log on to the FTP server. The FTP command will look for credentials in a file called .netrc in your home directory.
Add the following to it and then save, substitute your details where appropriate.
Additionally, this file needs the permissions set to 0600, which means that no-one else can intefere with it and therefore it should be trustworthy.
Once this file is created, we can test the connection by running the following commands to connect and create the remote storage directory. Obviously you should substitute the correct domain.
The next step is to script the FTP upload that will happen when a picture is saved to your chosen directory. So, create your script and mark it as executable
Use nano to add the following in to the newly created file. Again substituting details where appropriate.
You can now test your FTP script. Assuming that you have a jpg called test1.jpg in your Pictures directory, the command is as shown below. Once you have run the following, you should be able to see the picture on your remote server.
Incron is a system daemon that works a lot like cron. Most people have heard of cron which waits for a specified time before running a command or script; incron waits for a specified file system event before running a command or script.
incron is set up in a similar way to cron but it uses the incrontab instead of the crontab. To edit the incrontab you use the following command
You may find at this stage that you are not allowed to use incron. In such a case, simply edit the file /etc/incron.allow as root and add your user name to it. One user name per line. Once you can edit the incrontab, add the following to it.
There is much information to be found for incron on the Internet, but what that line says is essentially, "Watch your webcam directory and when a file is created in there, run your ftpuploader script passing it the name of the watched directory and file name that has been created.
You can test this simply by copying an image into your web cam directory. It should automagically appear on the remote server.