0

In below batch file, where the date is 2015_01_21 is a folder named by date on ftp, and the csv file is also having the date in name

How can i get this changed automatically, if i have to run this batch file through task scheduler daily?

ftp.exe -s:%0   
open 111.11.111.11   
Username  
Password

get Samle/2015_01_21/Samle_AB20150121.csv.gz  
get Samle/2015_01_21_ABCD/Samle_AB210115.csv.gz

quit
Community
  • 1
  • 1
Arvind Rai
  • 21
  • 2

2 Answers2

0

For more info check this

@echo off
pushd "%temp%"
makecab /D RptFileName=~.rpt /D InfFileName=~.inf /f nul >nul
for /f "tokens=3-7" %%a in ('find /i "makecab"^<~.rpt') do (
   set "current-date=%%e-%%b-%%c"
   set "current-time=%%d"
   set "weekday=%%a"
)
del ~.*
popd
for /f "tokens=1,2,3 delims=-" %%a in ("%current-date% ") do (
    set year=%%a
    set mon=%%b
    set day=%%c
)



if /i %mon% equ jan set mon=01
if /i %mon% equ feb set mon=02
if /i %mon% equ mar set mon=03
if /i %mon% equ apr set mon=04
if /i %mon% equ may set mon=05
if /i %mon% equ jun set mon=06
if /i %mon% equ jul set mon=07
if /i %mon% equ aug set mon=08
if /i %mon% equ sep set mon=09
if /i %mon% equ oct set mon=10
if /i %mon% equ nov set mon=11
if /i %mon% equ dec set mon=12

echo %mon% %day% %year%

break>temp.ftp
(
  echo open 111.11.111.11 
  echo username
  echo password

  rem ftp.exe supports wildcards so you can change AB to *
  rem echo get Samle/%year%_%mon%_%day%/Samle_*%year%%mon%%day%.csv.gz
  rem echo get Samle/%year%_%mon%_%day%_*/Samle_*%year%%mon%%day%.csv.gz

  rem if AB and ABCD strings are possible to change use the two lines above
  echo get Samle/%year%_%mon%_%day%/Samle_*%year%%mon%%day%.csv.gz
  echo get Samle/%year%_%mon%_%day%_ABCD/Samle_AB%year%%mon%%day%.csv.gz
)>>temp.ftp

ftp -s:temp.ftp
del /q /f temp.ftp
Community
  • 1
  • 1
npocmaka
  • 55,367
  • 18
  • 148
  • 187
0

To be dynamic with the dates, you'd be better with a temp file to pass to ftp rather than passing the bat itself. Try this.

@echo off
setlocal
for /f "skip=1 tokens=1-3" %%a in ('WMIC PATH win32_localtime get day^,month^,year') do  (
    if "%%a" neq "" (
        set day=%a
        set month=%b
        set year=%c
    )
)

set ftpfile=%tmp%\ftpfile.txt

echo open 111.11.111.11>%ftpfile%
echo Username>>%ftpfile%
echo Password>>%ftpfile%

echo get Samle/%year%_%month%_%day%/Samle_AB%year%%month%%day%.csv.gz>>%ftpfile%
echo get Samle/%year%_%month%_%day%_ABCD/Samle_AB%day%%month%%year:~-2%.csv.gz>>%ftpfile%

echo quit>>%ftpfile%

ftp.exe -s:%ftpfile%
del %ftpfile%
Scott C
  • 1,660
  • 1
  • 11
  • 18