home Mail List
Info
Info
Meetings
Goals
Upcoming
Projects
FAQ
Security
Links

[Date Prev][Date Next] [Chronological] [Thread] [Top]

[NMLUG] Move files via FTP



You might want to use -cmin to get changed time, not access time.  This 
might need some tweeking, because I haven't actually set up a test 
environment or actually tried find like that.

---
#!/bin/bash

dir_scan="/home/figment/ftp"    # $1 is directory to check in
ftp_host="ftp.local.com"    # host to put file
ftp_dir="subdirectory"    # directory on ftp host to put file

cd $dir_scan
for file in `find . -cmin +15`; do
  file_exist='( echo "cd $ftp_dir" ; echo " ; echo "quit" ) | ftp $ftp_host 
| grep $file`
  if [ "$file_exist" ]; then echo | mail -s "ftp script:replacing $file" 
notify@local.com ; fi
  ( echo "cd $ftp_dir" ; echo "put $file" ; echo "quit" ) | ftp $ftp_host
  mv $file ../backup
done
---

disclaimer: this is just a figment of your imagination, I'm not really here.

----- Original Message ----- 
From: Tim Emerick
To: nmglug@nmglug.org ; nmlug nmlug
Sent: Wednesday, July 05, 2006 5:13 PM
Subject: [NMLUG] Move files via FTP


I have a small project that I need some help with.  My bash scripting skills 
are terrible and I haven't been able to find a utility to do what I want 
which is this in a nutshell.

Here's some pseudo-code:

1. Look at a particular directory on local computer.
2. List all files that are older than 15 minutes (file might still be in the 
process of creation)
3. Copy those files to an FTP server that requires a username/password 
combo.
4. If the file already exists on the FTP server then throw somebody an email 
letting them know.
5. If the transfer is successful then delete the original (or move it to 
another directory).

I would like to run this every hour via cron.

Anything out there already existing?

Thanks!

Tim

PS.  Doing a little googling while I was composing helped me figure out a 
couple of things.

1. I can get a listing of files older than 15 minutes by using the 
following.  find . -amin +15

2. I can use .netrc to automagically login to the remote ftp server with my 
credentials.

3.  How do I do 2 things with my list of found files???  (ftp put and then 
delete/move)?

4. How do I get an email of just file tranfer errors?  (file already exists, 
etc)


Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls. Great rates 
starting at 1?/min.



_______________________________________________
NMLUG mailing list
NMLUG@nmlug.org
http://www.nmlug.org/mailman/listinfo/nmlug 





Please send sugestions and comments to webmaster@nmlug.org.
Valid XHTML 1.1! Valid CSS! Powered by Debian Powered by Apache