|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
FTP Script download files by date
I use ScriptFTP and am looking to download files daily from one server and upload them to another. I only want to download files that were created the day before and cannot figure out how to download just those files.
Example: I have 5000 files on the master server with 1200 of them with a date stamp of 12-15-06, I only want to download those files. |
|
#2
|
|||
|
|||
|
A script to try ftp grab files by date
#! /usr/bin/ksh
# # Setup a few variables try this SYSTEM=somehost USER=joeblow PASSWORD=******* DIRECTORY=tmp tmpfile=/tmp/ftpdir$$ thisyear=$(date +%Y) today=$(datecalc -j $(date "+%Y %m %d")) Jan=01 Feb=02 Mar=03 Apr=04 May=05 Jun=06 Jul=07 Aug=08 Sep=09 Oct=10 Nov=11 Dec=12 # # Get a copy of the remote dir output in a local file # called $tmpfile and attach that file to stdin for reading exec 5>&1 >$tmpfile 4>&1 ftp -nv >&4 2>&4 |& print -p open $SYSTEM print -p user $USER $PASSWORD print -p cd $DIRECTORY print -p dir print -p bye wait exec >&5 2>&1 < $tmpfile # # Ignore lines until we get a line that starts with 150 IFS="" looking=1 while ((looking)) ; do read line word1=${line%%${line##+([! ])}} [[ $word1 = 150 ]] && looking=0 done # # Loop getting lines that start with a "-" # Then delete some leading fields { IFS="" while read line ; do char1=${line%%${line#?}} [[ $char1 != - ]] && continue line="${line##+([! ])}" line="${line##+([ ])}" line="${line##+([! ])}" line="${line##+([ ])}" line="${line##+([! ])}" line="${line##+([ ])}" line="${line##+([! ])}" line="${line##+([ ])}" line="${line##+([! ])}" line="${line##+([ ])}" echo "$line" done ; } | { # # Second loop reads selected and shortened lines, # Computes the date and may get the file IFS=" " exec 4>&1 ftp -nv >&4 2>&4 |& print -p open $SYSTEM print -p user $USER $PASSWORD print -p cd $DIRECTORY while read month day swing name ; do eval month=\$$month if [[ $swing = *:* ]] ; then year=$thisyear else year=$swing fi julian=$(datecalc -j $year $month $day) if ((julian > (today-2))) ; then print -p get $name fi done print -p bye wait } rm $tmpfile exit 0 |
![]() |
| Viewing: Dev Shed Forums > System Administration > FTP Help > FTP Script download files by date |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|