We help IT Professionals succeed at work.

Get CSV file via ftp with todays date via a batch file

I am trying to extract a file that gets generated on our system each day via a batch file, the file is a CSV file. I need to GET the file via FTP, the file name will have today's date in each day, so for example if the file was run through on the 15th June 2010 the format of the file name must be 150610.CSV

Can anyone please help me with this dilema I am having as can not get it anything to work.

Thanks
Comment
Watch Question

If you can use powershell, I can help you out as it has an FTP module.

Commented:
OK.  To get the date in the right format you can follow the instructions in my article here to get the components of the date:

http://www.experts-exchange.com/articles/OS/Microsoft_Operating_Systems/MS_DOS/Using-dates-in-batch-files-scripts.html

Then you can use an ftp script like the ones I have here.  The easiest is to use "method 3" from this page since you can then use the variable you set to the date in the script easily.

http://scripts.dragon-it.co.uk/links/batch-ftp-scripting

Can elaborate more if you want me to.

Steve
Top Expert 2007

Commented:
Essentially, you supply a script file, and then a calling batch file:The script file would have something like:open ftp.mysite.comuserguestguestlcd c:\DownloadFoldercd  UploadFolderbinaryget %1quit The batch file could have something like:  @echo off  set filename=%date:~3,2%%date:~0,2%%date:~-2%.CSV  ftp -i -s:c:\scripts\myFTPFile.scr %filename%Some good FTP script sites:  http://www.robvanderwoude.com/ftp.php  http://support.microsoft.com/kb/96269
Commented:
Which should be something like this:

@echo off
echo wscript.echo right(100+day(date),2) ^& "," ^& right(100+month(date),2) ^& "," ^& right(year(date),2)>"%temp%\dateparts.vbs"
for /f "tokens=1" %%a in ('cscript //nologo "%temp%\dateparts.vbs"') do set ddmmyy=%%a

echo The date is %ddmmyy%

@echo off
(echo open x.x.x.x
echo user username password
echo cd /source/path
ech lcd c:\destination\path
echo bin
echo get %ddmmyy%.csv
echo quit
) | ftp -n -i

Steve

http://www.experts-exchange.com/articles/OS/Microsoft_Operating_Systems/MS_DOS/Using-dates-in-batch-files-scripts.html

Commented:
Sorry sirbounty hadn't refreshed and seen your example.  I tend to shy away from using %date:...% only because of differences of date formats for different users, scheduled tasks, different OS computers etc. but if it works for the specific situation fine!

That was all one script above btw, the second @Echo off can be removed.

Steve

Author

Commented:
I found this solution the easiest to follow and got my files extracted within moments.

Commented:
No proiblem, glad it helped.

Steve