Solved

Script FTP download with a Modified Date restriction.

Posted on 2007-03-20
3
229 Views
Last Modified: 2010-04-16
I need to write a script that will be used to FTP files on a nightly basis. The one issue i am having is finding a solution that will allow me specify in the script to only download files modified after a certain date.

For example the FTP directory is over 13 GB of data. I only need files that have a Date Modified after Jan1, 2007. It does not appear that I can specify this with the Windows FTP, and I have also tried CoreFTP (it only allows not to overwrite or to overwrite.

Thank you for any suggestions.
0
Comment
Question by:dolphan2013
  • 2
3 Comments
 
LVL 30

Accepted Solution

by:
SteveGTR earned 500 total points
Comment Utility
Try this. You'll want to change the variables at the top of the files of course. Also check the directory output produced on your server. See the note before the for statement:

@echo off

setlocal

set compDate=20070101

set server=ftp.microsoft.com
set user=anonymous
set pass=test@test.com
set fileDir=misc

(echo %user%)>_temp.txt
(echo %pass%)>>_temp.txt
if not "%fileDir%"=="" (echo cd %fileDir%)>>_temp.txt
(echo dir)>>_temp.txt
(echo bye)>>_temp.txt

echo Gathering file information...
ftp -s:_temp.txt %server% >_out.txt

(echo %user%)>_temp.txt
(echo %pass%)>>_temp.txt
if not "%fileDir%"=="" (echo cd %fileDir%)>>_temp.txt
(echo binary)>>_temp.txt

set found=

REM ** Relies on output looking like this:
REM ** dr-xr-xr-x   1 owner    group               0 Feb  1  2006 beckyk
for /f "tokens=6-8*" %%a in ('type _out.txt ^| findstr /V ^^dr- ^| findstr owner') do call :PROCFILE %%a %%b %%c "%%d"

if "%found%"=="" echo No files found&goto CLEANUP

(echo bye)>>_temp.txt

echo Downloading files...
ftp -s:_temp.txt %server%

:CLEANUP

del _temp.txt 2>NUL
del _out.txt 2>NUL

goto :EOF

:PROCFILE

if "%~4"=="" goto :EOF

call :CONVMONTH "%1"

if "%mm%"=="" goto :EOF

set dd=%~2
if 1%dd% LSS 100 set dd=0%~2%

set fileDate=%~3%mm%%dd%

if /i "%compDate%" LSS "%fileDate%" set found=Y&echo Downloading %~4&(echo get %~4)>>_temp.txt

goto :EOF

:CONVMONTH

if /i "%~1"=="Jan" set mm=01&goto :EOF
if /i "%~1"=="Feb" set mm=02&goto :EOF
if /i "%~1"=="Mar" set mm=03&goto :EOF
if /i "%~1"=="Apr" set mm=04&goto :EOF
if /i "%~1"=="May" set mm=05&goto :EOF
if /i "%~1"=="Jun" set mm=06&goto :EOF
if /i "%~1"=="Jul" set mm=07&goto :EOF
if /i "%~1"=="Aug" set mm=08&goto :EOF
if /i "%~1"=="Sep" set mm=09&goto :EOF
if /i "%~1"=="Oct" set mm=10&goto :EOF
if /i "%~1"=="Nov" set mm=11&goto :EOF
if /i "%~1"=="Dec" set mm=12&goto :EOF

set mm=

goto :EOF

Good Luck,
Steve
0
 

Author Comment

by:dolphan2013
Comment Utility
Thanks for your help.
0
 
LVL 30

Expert Comment

by:SteveGTR
Comment Utility
You really need to adjust your grading habits. Please check out:

http://www.experts-exchange.com/help.jsp#hi20

The grading system is a joke as far as I'm concerned. You should always grade as an A. Doesn't cost you anything and doesn't create bad blood...
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This is an article about Leadership and accepting and adapting to new challenges. It focuses mostly on upgrading to Windows 10.
Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now