Solved

Script FTP download with a Modified Date restriction.

Posted on 2007-03-20
3
240 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
No single Antivirus application (despite claims by manufacturers) will catch or protect you from all Virus / Malware or Spyware threats. That doesn't stop you from further protecting yourself however - and this article is to show you how.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

732 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