Page 1 of 1
Batch Script to locate specified path on FTP server
Posted: 09 Jul 2015 04:27
by SantoshVetsa
Hi Team,
Please need your valuable support to resolve my concern.
Request : I want download files from FTP server but here requirement is we needs to specify the path basis on system date.
Ex : FTP path location -> cd /pgdata/2015-07-09<This folder having today's date> so this date will change every day
Here want to make the date folder name automate format (YYYY-MM-DD).
I have tried several ways but not able to crack kindly suggest.
FTP Text File
--------------
open XX.XXX.XX.XX
ftpuser
ftpuser123
cd /pgdata/2015-07-09<YYYY-DD-MM>
lcd d:\Reports
binary
prompt
Re: Batch Script to locate specified path on FTP server
Posted: 09 Jul 2015 10:55
by foxidrive
Getting the date, and into a certain format, is one of the most FAQ on the internet.
You will find dozens of ways if you search on this forum a little.
Re: Batch Script to locate specified path on FTP server
Posted: 10 Jul 2015 01:37
by SantoshVetsa
I have not found perfect solution, Any one please suggest me if it's possible to make it.
Re: Batch Script to locate specified path on FTP server
Posted: 10 Jul 2015 06:27
by Squashman
Open up a command prompt and type:echo %date%
Re: Batch Script to locate specified path on FTP server
Posted: 10 Jul 2015 09:12
by ShadowThief
http://stackoverflow.com/questions/2030 ... 116#203116Specifically, the third one with the wmic code. Guaranteed to work regardless of where in the world you live.
Re: Batch Script to locate specified path on FTP server
Posted: 28 Jul 2015 01:24
by SantoshVetsa
How to call this ECHO command on mentioned remote path FTP script, Please revert me if possible.
Re: Batch Script to locate specified path on FTP server
Posted: 28 Jul 2015 02:22
by foxidrive
Test this:
Code: Select all
@echo off
rem The four lines below will give you reliable YY DD MM YYYY HH Min Sec MS variables in XP Pro and higher.
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%" & set "MS=%dt:~15,3%"
set "datestamp=%YYYY%-%DD%-%MM%"
set "ftpHost=XX.XXX.XX.XX"
set "ftpUser=ftpuser"
set "ftpPwd=ftpuser123"
set "ftpRemoteDir=/pgdata/%datestamp%"
set "ftpLocalDir=%cd%"
(
echo open %ftpHost%
echo %ftpUser%
echo %ftpPwd%
echo lcd d:\Reports
echo cd %ftpRemoteDir%
echo binary
echo dir
echo bye
)>"%ftpLocalDir%\temp.ftp"
ftp.exe -i -s:"%ftpLocalDir%\temp.ftp"
del "%ftpLocalDir%\temp.ftp"
pause
Re: Batch Script to locate specified path on FTP server
Posted: 28 Jul 2015 04:18
by SantoshVetsa
Wow.. Awesome Bro.. It's working perfectly
But downloading is not happening, I have included mget command and reports are reflecting on screen only but not downloading.
Please need your support to find the solution for downloading as well below sample output details for your reference.
ftp> mget *.csv
200 Switching to Binary mode.
mget TDR_UTIBA_20150728_0014.csv? bye
mget TDR_UTIBA_20150728_0029.csv? mget TDR_UTIBA_20150728_0044.csv? mget TDR_UTIBA_20150728_0059.csv?
Re: Batch Script to locate specified path on FTP server
Posted: 28 Jul 2015 04:29
by SantoshVetsa
Please ignore my earlier comments as I'm able to generate and download, My requirement is fulfilled 10000%.
Thanks a TON for your such a wonderful support.