?
Solved

Script FTP download with a Modified Date restriction.

Posted on 2007-03-20
3
Medium Priority
?
244 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 1500 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

Optimum High-Definition Video Viewing and Control

The ATEN VM0404HA 4x4 4K HDMI Matrix Switch supports 4K resolutions of UHD (3840 x 2160) and DCI (4096 x 2160) with refresh rates of 30 Hz (4:4:4) and 60 Hz (4:2:0). It is ideal for applications where the routing of 4K digital signals is required.

Question has a verified solution.

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

I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

765 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