简体   繁体   中英

Batch Script for Download files from FTP server with Condition

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..

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM