Register
It is currently Wed Dec 13, 2017 12:49 pm

Ftp check every n minutes and download if new file exists.


All times are UTC - 6 hours


Post new topic Reply to topic  [ 8 posts ] 
Author Message
 PostPosted: Tue Jan 26, 2016 1:35 pm   

Joined: Tue Jan 26, 2016 12:11 pm
Posts: 5
Ftp folder is named ftp.domain.com/cam/%Y%m%d/rec001/, and local folder is named ~/cam/%Y%m/%d/

The local folder will need to be checked if it exists before download begins, and if it does not exitst be created.

I have a network camera which i share with my neighbour that uploads it´s videos to an ftp server which both i and him have access to. Sometimes he chose to delete videos he deem irrelevant before i even get to see them.

I would like a cronjob that downloaded all new (compared to my local folder) videos before he had a chance to delete them. He doesn't delete very often, but when he does he sometimes clean everything out including the ftp folder (but that is recreated when a new video is recorded).

So : A script that compares local filenames in a folder with an ftp folder, and if a new file exist it is downloaded.


Top
 Profile  
 PostPosted: Tue Jan 26, 2016 3:49 pm   

Joined: Mon Oct 20, 2014 9:53 am
Posts: 560
Do not use ftp.
Read this: http://mywiki.wooledge.org/FtpMustDie

If ssh available:
Code:
frequency=$((60*60)) # 1 hour; we need seconds
while true; do
    rsync -avz remotehost:/path/to/pics/  /local/path/to/pics
done


Top
 Profile  
 PostPosted: Wed Jan 27, 2016 11:17 am   
Moderator
User avatar

Joined: Wed May 03, 2006 2:05 pm
Posts: 273
I agree with uhelp that FTP is bad, but sometimes, especially if you don't control the environment, it's all you've got to work with.

** If ssh access is available, it's definitely a better option to be able to use something like rsync or scp.

If you absolutely have to use FTP, look into ncftp or lftp. They both have the option to specify the user and password on the command line (another bad idea, but sometimes necessary), and ncftp makes it even more simple with the ncftpget command. Here's a good article on ncftp: http://www.techrepublic.com/article/aut ... fficiency/

I hope this helps!


Top
 Profile YIM  
 PostPosted: Thu Jan 28, 2016 5:39 pm   

Joined: Tue Jan 26, 2016 12:11 pm
Posts: 5
Ftp is not my first choice either, but the network camera only offers ftp-uploads. First i tried to convert the h.264 stream via VLC and feed it to a program called motion which handles motion detection, but i didn't get that to work..

But..

My question was if anyone has a script laying around that does what i wrote in my opening post.


Top
 Profile  
 PostPosted: Thu Jan 28, 2016 5:48 pm   

Joined: Tue Jan 26, 2016 12:11 pm
Posts: 5
Maybe i misunderstood. I have a ssh shell with root privileges, but the files are on a ftp-server. So the only way to download is to use a ftp-client.


Top
 Profile  
 PostPosted: Fri Jan 29, 2016 9:19 am   
Moderator
User avatar

Joined: Wed May 03, 2006 2:05 pm
Posts: 273
Hey fr3d!

Ok, so with SSH access, you can do something like what's in uhelp's rsync example. To automate it, you'll want to set up ssh keys for authentication, or use something like 'sshpass' (a little less secure). rsync would do all the magic to check for new files for you.

I don't have anything laying around, but I did mention lftp. It looks like something like this might work for you:
Code:
lftp -e 'mirror -n /remote/path/ /local/path/' -u user,password ftp.yourdomain.com


I hope this helps!


Top
 Profile YIM  
 PostPosted: Sat Jan 30, 2016 1:23 pm   

Joined: Tue Jan 26, 2016 12:11 pm
Posts: 5
jeo wrote:
Hey fr3d!

Ok, so with SSH access, you can do something like what's in uhelp's rsync example. To automate it, you'll want to set up ssh keys for authentication, or use something like 'sshpass' (a little less secure). rsync would do all the magic to check for new files for you.

I don't have anything laying around, but I did mention lftp. It looks like something like this might work for you:
Code:
lftp -e 'mirror -n /remote/path/ /local/path/' -u user,password ftp.yourdomain.com


I hope this helps!


Thank you, it worked. I can send you $5 worth of bitcoin as a thank you if you give me an adress..


Top
 Profile  
 PostPosted: Sat Jan 30, 2016 1:27 pm   

Joined: Tue Jan 26, 2016 12:11 pm
Posts: 5
A bitcoin adress that is.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 17 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP