0

Please need your support to crack the batch script for downloading files from FTP server with below condition.

Requirement is need to get the current directory folder name basis on date format like "YYYY-MM-DD".

I have tried to use the SET command but same is not working, Pl find below complete script details for your reference. Anyone please suggest and provide me the solution.

ftp
open 11.111.13.11
username
password
***cd /data/ %Today% (Folder Name- Automatic date format required like "YYYY-MM-DD")***
lcd d:\
binary
prompt
mget *.csv
bye

script for Current Date folder

SET Today=%Date:~10,4%-%Date:~4,2%-%Date:~7,2%
echo %Today%

Please let me know if any more details required..

Bacon Bits
  • 30,782
  • 5
  • 59
  • 66
Santosh
  • 11
  • 1
  • 2

1 Answers1

0

You'll need to build the script file dynamically and then call it.

@echo off
SET Today=%Date:~10,4%-%Date:~4,2%-%Date:~7,2%
SET ftpscript=%TEMP%\ftpscript.txt

echo open 11.111.13.11 > %ftpscript%
echo username >> %ftpscript%
echo password >> %ftpscript%
echo cd /data/%Today% >> %ftpscript%
echo lcd d:\ >> %ftpscript%
echo binary >> %ftpscript%
echo prompt >> %ftpscript%
echo mget *.csv >> %ftpscript%
echo bye >> %ftpscript%

ftp.exe -s:%ftpscript%

Note the first echo overwrites and the rest append.

Bacon Bits
  • 30,782
  • 5
  • 59
  • 66
  • @Santosh Does your script file literally say, `cd /data/%Today%`? It shouldn't unless you didn't run `SET Today=%Date:~10,4%-%Date:~4,2%-%Date:~7,2%` first. It's not clear to me exactly what you're doing, really. – Bacon Bits May 27 '15 at 15:18
  • I want to locate the remote path folder like current date format (YYYY-MM-DD) since remote server reports are available basis on date folder through mentioned FTP script, How can simply to fulfil my requirement. Please need your support on the same since i'm new to batch script and unable to crack it – Santosh Jul 28 '15 at 07:59