kiteboywales
Posts: 4
Joined: Wed May 15, 2013 12:03 pm

Scripting Advice

Mon Oct 09, 2017 11:27 am

Hi all

I have a raspberry pi w thats taking a photo when the pi starts and placing the jpg in /home/pi/images

That script seems to be working ok when the pi boots

What I would like to do is have another script that checks this folder and then ftps all the jpgs to a server

Im using the following to do that at the moment using ncftpput

Code: Select all


#!/bin/bash
sleep 5
ncftpput -F -DD -S .tmp -u ******** -p ******* myserver.com /TestCamera /home/pi/images/*.jpg
echo uploading photos please wait......
while true ; do ./home/pi/ftpupload.sh & sleep 5; done
When running this by doing ./ftupload.sh from the command line it seems to upload any images in that folder and delete them when complete...great - exactly what I would llike

When there are no jpgs in that folder I get an error "/home/pi/ftpupload.sh: No such file or directory" and when new jpgs go i there even though the script re-runs every 5secs it doesnt pick anything new up

What am I doing wrong and what would be the best way start this on boot??

Newbie here so go slow please

Thanks for any advice

Martin Frezman
Posts: 1020
Joined: Mon Oct 31, 2016 10:05 am

Re: Scripting Advice

Mon Oct 09, 2017 12:31 pm

I think it would be simpler to use a shared directory method instead of FTP.

Easiest is to make the directory on the server (which I'm guessing is either Windows or Linux) shared, then have your picture taking routine write files directly to that directory.

BTW, I've used FTP a lot back in the day - it had its place - and I've used the NCFTP tools a lot too, but not in a long time. It doesn't seem to be necessary anymore.
If this post appears in the wrong forums category, my apologies.

pcmanbob
Posts: 6960
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Scripting Advice

Mon Oct 09, 2017 1:11 pm

You could do a check first to see if there are any files in the directory and only run your upload part of the script if there are any.

some thing along the lines of this

Code: Select all

#!/bin/bash
sleep 5
file="/home/pi/images/*.jpg"

if [ -e "$file" ]
then
    ncftpput -F -DD -S .tmp -u ******** -p ******* myserver.com /TestCamera /home/pi/images/*.jpg
    echo uploading photos please wait......
    
 else
	echo "$file not found
    
while true ; do ./home/pi/ftpupload.sh & sleep 5; done
untested code.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

kiteboywales
Posts: 4
Joined: Wed May 15, 2013 12:03 pm

Re: Scripting Advice

Mon Oct 09, 2017 1:47 pm

Thanks all - will try that bit of code instead

Has to be FTP im afraid.......... as far as I know anyway - its a remote linux server

Im sure you could dropbox it or something similar but theres scripts on that server checking for files too

FTP is a standard although albeit not the most secure

Will give that a go

Thanks again

Martin Frezman
Posts: 1020
Joined: Mon Oct 31, 2016 10:05 am

Re: Scripting Advice

Mon Oct 09, 2017 2:06 pm

Is SSH an option?

As you say, FTP is completely insecure - as well as hard to implement (if this comment makes no sense to you, just ignore it).

If SSH is usable, then there are several possibilities there - including (best) sshfs.
If this post appears in the wrong forums category, my apologies.

Return to “Beginners”