Search code examples
javawebcamfilezilla

Is it possible to automatically upload files when created to a web server?


I am working on a project using a Raspberry Pi and a web cam to detect motion.

I have got it to a stage whereby it takes an image and saves it on my computer. What I am wondering is, is it possible to let FileZilla automatically upload the image to my webserver when a new image is taken? Or is there any other ways that I could achieve this?


Solution

  • Since the post is tagged java, I'm assuming that you're using a Java program already or have the basic knowledge to create a Java program.

    On to the answer: yes, you basically have two options.
    1. Upload from within the Java program. FTP is probably the easiest since most web servers will have an FTP server running. Here is a tutorial you can use: http://www.codejava.net/java-se/networking/ftp/java-ftp-file-upload-tutorial-and-example
    2. Use another utility outside your Java program to upload the file to your webserver. rsync would be the tool of my choice (tutorial here). When on a Linux machine (for example, the Pi) or a Mac, you can run a script that syncs the content of a local folder to a remote folder every x seconds:
    while true; do <rsync command hier> sleep 5s; done
    Note that that sleep period shouldn't be too short or you'll end up running multiple instances of rsync.
    When on a Windows machine, you need to find another way to run a periodic process to trigger the rsync.