Computer Hope
Software => Computer software => Topic started by: swinters on September 29, 2009, 01:42:35 PM
-
I have a file that gets exported daily. It always ends with todays date, i.e. support_20090929.csv. I've tried several variables to pull in the current date each day in my ftp batch file without any luck. Below are some examples of what I've tried. If anyone has any idea how to do this I'd appreciate the help.
put \\slnk1001a_support_&date&.csv /slnk1001a/slnk1001a_support&date&.csv
put \\slnk1001a_support_$YYYYMMDD$.csv /slnk1001a/slnk1001a_support_$YYYYMMDD$.csv
put \\slnk1001a_support_%date:~10,4%%date:~4,2%%date:~7,2%.csv /slnk1001a/slnk1001a_support_%date:~10,4%%date:~4,2%%date:~7,2%.csv
-
Not clear what "put" means
Command prompt says it is not a command.
Try to explain what you want in some more detail.
-
Its taking the file from my server and ftp'ing it to another vendor...what I do currently is change the date manually everytime. Below is the .bat file code and the ftp.txt file it calls is below that. I'm trying to find code that will replace the 20090929 each day with the current date so that I don't have to key it manully each time.
ftp.bat
ftp -n -i -d -g -s:S:\BatchFiles\FTP.txt ftp.site.com
ftp.txt
put S:\EXCEL\slnk1001a_support_20090929.csv /slnk1001a/slnk1001a_support_20090929.csv
-
Your third example looks as though it ought to work.
What output are you getting?
-
Part of a batch to use current date could be like this:
REM Below is an exercise to show...
REM date string manipulation.
DATE /T
echo %date:~4,2%
echo %date:~7,2%
echo %date:~10,4%
echo %date:~4,2%>MM.TMP
echo %date:~7,2%>DD.TMP
echo %date:~10,4%>YYYY.TMP
set /P MM= <MM.TMP
SET /P DD= <DD.TMP
SET /P YYYY= <YYYY.TMP
ECHO %MM%%DD%%YYYY%
-
Below is an excert from the third example. I've also included what it looks like when i have the date hard coded in and the ftp is successful.
550 /slnk1001a/slnk1001a_disconnect_%date:~10,4%%date:~4,2%%date:~7,2%.csv: The
filename, directory name, or volume label syntax is incorrect.
---> STOR /slnk1001a/slnk1001a_disconnect_20090930.csv
150 Opening ASCII mode data connection for /slnk1001a/slnk1001a_disconnect_20090
930.csv.
226 Transfer complete.
ftp: 75671 bytes sent in 0.45Seconds 167.04Kbytes/sec.
Thanks!
-
OK. The problem appears to occur because FTP is unable to expand the variable. You may need to CALL the PUT command. Something like:
call:put \\slnk1001a_support_%date:~10,4%%date:~4,2%%date:~7,2%.csv /slnk1001a/slnk1001a_support_%date:~10,4%%date:~4,2%%date:~7,2%.csv
:put
put %*
-
Hi Oldun - Thank you once again for helping me. I tried the new code you suggested and still get an error...little different though.
ftp> call:put S:\slnk1001a_support_%date:~10,4%date:~4,2%date:~7,2%.csv /slnk1001a/slnk1001a_support_%date:~1
0,4%date:~4,2%date:~7,2%.csv
Invalid command.
-
Change your FTP to use the mput comand.
PROMPT
lcd put S:\EXCEL\
mput *.csv
this will send all the files named .csv in that folder.
If you only want to send todays file then setup a temp folder to move all the old stuff out of the working folder leaving todays file only. After the FTP move the file to the temp folder for storage and start a new blank file for the next day.
-
Sorry. Try rewriting your ftp.bat file like this:
NOTE: The Echo line should be on a single line.
@Echo Off
Echo put \\slnk1001a_support_%date:~10,4%%date:~4,2%%date:~7,2%.csv /slnk1001a/slnk1001a_support_%date:~10,4%%date:~4,2%%date:~7,2%.csv >S:\BatchFiles\ftp.txt
ftp -n -i -d -g -s:S:\BatchFiles\FTP.txt ftp.site.com
-
I am presuming that the %date% format is the US style, Day dd/mm/yyyy.
why not shorten the long line thus and make things more readable
set YYYYMMDD=%date:~10,4%%date:~4,2%%date:~7,2%
set file=slnk1001a_support_%YYYYMMDD%.csv
set path1=\\%file%
set path2=/slnk1001a/%file%
set ftptxtfile=S:\BatchFiles\ftp.txt
Echo put %path1% %path2% >%ftptxtfile%
ftp -n -i -d -g -s:%ftptxtfile% ftp.site.com
-
Hi Oldun - Thanks so much for the reply. I finally got some time to play with it this morning and it worked perfectly. No more manual FTP'ing. Thanks so much!!!!