Solved

Script FTP download with a Modified Date restriction.

Posted on 2007-03-20
3
238 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
ID: 18757051
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
ID: 19066774
Thanks for your help.
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 19067417
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

Building an interactive eFuture classroom

Watch and learn how ATEN provided a total control system solution including seamless switching matrix switch, HDBaseT extenders, PDU, lighting control to build an interactive eFuture classroom.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
In this article, I will show you HOW TO: Install VMware Tools for Windows on a VMware Windows virtual machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, using the VMware Host Client. The virtual machine has Windows Server 2016 instal…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

761 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