MS DOS File Loop FTP

Hi,

I have no DOS knowledge. What I am trying to do is to copy a file from an FTP site to my local computer. I already have this code however the problem is that the file name that I wish to copy from our data provider has a different & random number assigned to it every day.

Below is an example of two files names. It is the first number that is casuing me problems.

41936811_TAPLATRI_20100420_Global_Barcap_HY_Index.csv
41552871_TAPLATRI_20100419_Global_Barcap_HY_Index.csv

So what I thougt would be the best thing to do is to loop through the folder and using a bit of string manipluation find the file which contains the name "TAPLATRI" (there is only one file with this name) then copy it to my local computer. However like I have said I have no DOS knowledge and am not sure how to do this?

My Bactch File
G:
G:\Shared\Mark\Scheduled Tasks

ftp -s:txtLehman.scp indexftp.barcap.com

My Text File
username
password

prompt n
cd point
cd download

get 41936811_TAPLATRI_20100420_Global_Barcap_HY_Index.csv "G:\Shared\Mark\FTP\TAPLATRI_20100420_Global_Barcap_HY_Index.csv" overwrite

quit




Thanks for any help,

Mark



username
password

prompt n
cd point
cd download

get 41936811_TAPLATRI_20100420_Global_Barcap_HY_Index.csv "G:\Shared\Mark\FTP\TAPLATRI_20100420_Global_Barcap_HY_Index.csv" overwrite 

quit

Open in new window

mcs26Asked:
Who is Participating?
 
woolmilkporcCommented:
Couldn't a simple "mget" (=multiple get allowing wildcards) do the trick?
mget *_TAPLATRI_20100420_Global_Barcap_HY_Index.csv "G:\Shared\Mark\FTP\" overwrite
Since source and target filename are identical, I assume there is no need to specify the target filename, specifying the directory alone should be enough.
Not sure though ...
wmp
 
0
 
mcs26Author Commented:
Hi woolmilkporc,

Thanks replying thats perfect! One thing I forgot to mention was the file name is RandomNumber_TAPLATRI_yyyymmdd_rest. So today I need the file name TAPLATRI_20100426 How would I do that?

Thanks
0
 
woolmilkporcCommented:
Well, try
mget *_TAPLATRI_*_Global_Barcap_HY_Index.csv  
Should work!
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
mcs26Author Commented:
Its works but it downloads all the old TAPLATRI files, I only want it to copy todays file over?
0
 
cyberkiwiCommented:
At the top of your batch file, add

FOR /F “TOKENS=1* DELIMS= ” %%A IN (’DATE/T’) DO SET CDATE=%%B
FOR /F “TOKENS=1,2 eol=/ DELIMS=/ ” %%A IN (’DATE/T’) DO SET mm=%%B
FOR /F “TOKENS=1,2 DELIMS=/ eol=/” %%A IN (’echo %CDATE%’) DO SET dd=%%B
FOR /F “TOKENS=2,3 DELIMS=/ ” %%A IN (’echo %CDATE%’) DO SET yyyy=%%B
SET mydate=%yyyy%%mm%%dd%

get %_TAPLATRI_%mydate%_Global_Barcap_HY_Index.csv "G:\Shared\Mark\FTP\" overwrite
0
 
cyberkiwiCommented:
Oops... sorry got the get command wrong.
Use mcs26's, i.e.

mget *_TAPLATRI_%mydate%_Global_Barcap_HY_Index.csv "G:\Shared\Mark\FTP\" overwrite
0
 
mcs26Author Commented:
Hi Cyber Kiwi,

Thanks for replying. Am i supposed to put all the FOR commands into my text file or batch file?. If I put it at the top of my batch file it does not execute?

Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.