Storing d-link camera videos with FTP and a cron job

in camera •  7 years ago  (edited)

Residential surveillance cameras are all the rage lately, and I tried my hand at setting up the d-link. I noticed that a drawback is that they try to hook you into a subscription for their "cloud" storage feature. That sounded like a challenge to me.

So luckily many of these cameras come with a setting for FTP. With enough fiddling, an FTP server is a poor man's "cloud" storage, and I can manipulate the videos in ways I want. As you can see, I like putting "cloud" in quotes because, in this case, it feels like a buzz-word to me.

One of the drawbacks is that videos are huge. They can fill up disk space in a hurry. I'm not a fan of manually cleaning out videos each month or so. Luckily, a cron job came to the rescue. I wrote a php script that recursively cleans out the videos folder each month. Bada bing, bada boom, a fancy "cloud" for videos. Here's the breakdown.

Set up the FTP folder and user

First, I wanted to make sure that the cameras used a unique folder and FTP user so that I didn't get confused down the road (I am using the FTP provided by my website hosting). I made sure that the videos directory is in the home directory and not inside public_html. You don't want your videos in the public directory or else your camera might end up on Reddit or 4chan for all to see.

For that directory I made an FTP user locked down to that directory only. Again, security.

Put the FTP user info in d-links advanced settings

Log in to your camera's advanced settings area and look for FTP settings. Then put in your new FTP user's info. To save myself time, there's already a great write-up on these settings here:

http://support.dlink.ca/FAQView.aspx?f=L6hdnkoRQ%2Bn%2BcqSTzTAL1g%3D%3D

Assuming all is right, the test should automatically create/touch a new directory named after your camera's nickname. That folder then sets up its own structure for videos and snapshots inside of it, depending on your settings. The final folder structure will be something like this:

/home/meuser/cameras/kitchen/videos

and/or:

/home/meuser/cameras/kitchen/snapshots

Now for the cron job

So once those videos start firing off (like with motion detection), your account will fill up disk space, especially if you sync up more than one camera. So here's the script I made and dropped inside the home directory:

https://gist.github.com/jdabs/eb7bb3f3ba878d3c48242b9d2223162e

Since Steemit doesn't support embeds just yet, here's a picture for a quick glance at the code:

PSX_20180510_134252.jpg

Then I setup a cron job to execute that file as php once a month. The cron notation looks like this:

0 0 1 * * php /home/bagzinga/cron.php

That's all! It took a bit of tinkering, but I thought it was an enjoyable exercise that saves money. Enjoy!

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!