FTP Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsSystem AdministrationFTP Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old December 18th, 2006, 03:36 PM
tgruendler tgruendler is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2006
Posts: 2 tgruendler User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 12 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old January 3rd, 2008, 11:46 AM
molix molix is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Posts: 1 molix User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 m 22 sec
Reputation Power: 0
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationFTP Help > FTP Script download files by date


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway