Solved

Script FTP download with a Modified Date restriction.

Posted on 2007-03-20
3
233 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
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…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

803 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