Batch Script to locate specified path on FTP server

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
SantoshVetsa
Posts: 5
Joined: 09 Jul 2015 04:00

Batch Script to locate specified path on FTP server

#1 Post by SantoshVetsa » 09 Jul 2015 04:27

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch Script to locate specified path on FTP server

#2 Post by foxidrive » 09 Jul 2015 10:55

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.

SantoshVetsa
Posts: 5
Joined: 09 Jul 2015 04:00

Re: Batch Script to locate specified path on FTP server

#3 Post by SantoshVetsa » 10 Jul 2015 01:37

I have not found perfect solution, Any one please suggest me if it's possible to make it.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Batch Script to locate specified path on FTP server

#4 Post by Squashman » 10 Jul 2015 06:27

Open up a command prompt and type:echo %date%

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Batch Script to locate specified path on FTP server

#5 Post by ShadowThief » 10 Jul 2015 09:12

http://stackoverflow.com/questions/2030 ... 116#203116

Specifically, the third one with the wmic code. Guaranteed to work regardless of where in the world you live.

SantoshVetsa
Posts: 5
Joined: 09 Jul 2015 04:00

Re: Batch Script to locate specified path on FTP server

#6 Post by SantoshVetsa » 28 Jul 2015 01:24

How to call this ECHO command on mentioned remote path FTP script, Please revert me if possible.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch Script to locate specified path on FTP server

#7 Post by foxidrive » 28 Jul 2015 02:22

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

SantoshVetsa
Posts: 5
Joined: 09 Jul 2015 04:00

Re: Batch Script to locate specified path on FTP server

#8 Post by SantoshVetsa » 28 Jul 2015 04:18

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?

SantoshVetsa
Posts: 5
Joined: 09 Jul 2015 04:00

Re: Batch Script to locate specified path on FTP server

#9 Post by SantoshVetsa » 28 Jul 2015 04:29

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.

Post Reply