Lloyd Banks
Lloyd Banks

Reputation: 36648

Changing File Name in Auto Weekly FTP Download

I have a SCR file with the below commands

open myftp.myserver.com
myusername
mypassword
lcd "c:\myfolder"
cd webfolder
get myfile09202012

I run this script with a BAT file as a Windows Task once per week. This week, the file name to download is "myfile09202012". Next week, the file name would be "myfile09272012". How would I create a script to auto-generate the new file name every week?

Upvotes: 0

Views: 950

Answers (2)

Lloyd Banks
Lloyd Banks

Reputation: 36648

I ended up using the following convention

get myfile%date:~4,2%%date:~7,2%%date:~10%

If you type in the command 'echo %date%', you will receive today's date in the format 'Wed 10/10/2012' The string '%date:~4,2%' returns the above format at the 4th placeholder and returns the next 2 characters.

Upvotes: 0

SeanC
SeanC

Reputation: 15923

pipe the output of this batch file to your script file, then run the resulting script in the normal way.

@echo off
echo open myftp.myserver.com
echo myusername
echo mypassword
echo lcd "c:\myfolder"
echo cd webfolder
for /f "tokens=2-4 delims=/ " %%a in ('echo %date%') do echo get myfile%%a%%b%%c

it will use the current date to generate the filename

to incorporate the whole batch within another batch file, it would end up something like this:

@ECHO OFF
cd c:\myfolder
echo open myftp.myserver.com > mySCRfile.SCR 
echo myusername >> mySCRfile.SCR 
echo mypassword >> mySCRfile.SCR 
echo lcd "c:\myfolder" >> mySCRfile.SCR 
echo cd webfolder >> mySCRfile.SCR 
for /f "tokens=2-4 delims=/ " %%a in ('echo %date%') do echo get myfile%%a%%b%%c >> mySCRfile.SCR 
ftp -s:mySCRfile.SCR 

or

@ECHO OFF
cd c:\myfolder
call MakeTheScr > mySCRfile.SCR 
ftp -s:mySCRfile.SCR 

Upvotes: 1

Related Questions