cancel
Showing results for 
Search instead for 
Did you mean: 

Bat File

SOLVED
Go to solution
Sue OLoughlin
Occasional Visitor

Bat File

I have a .bat file on a Windows XP Pro platform that will FTP a file to another server. I would like to know how to rename the file by appending the current date to the filename before the put command.

Here is what I am doing/want to do:

OPEN server
dwftp
*****
lcd \\server\targetdir
status
PUT CURRDATA.txt CURRDATA_08252006.txt
bye

So, I need to put the date in a variable and append the variable to the filename somehow. I don't want to have to edit the .bat daily to change the date. The .bat file will run automatically each evening.

Thank you.

Sue
1 REPLY
Jon Finley
Honored Contributor
Solution

Re: Bat File

Try this:

------------------------------------------
rem .: if your date has '/' in the date, they need to be stripped out.
for /f "delims='/'" %%i in ('%date%') do
set my_date=%%i%%j%%k
set my_file=CURRDATA%my_date%.txt

OPEN server
dwftp

lcd \\server\targetdir
status
PUT CURRDATA.txt %my_file%
bye
-------------------------------------------

If you need to use a script file to run rather than issue the commands directly, you can echo the commands out to a file like below:

---------------------------------------
set /P my_loc="Please enter FTP site: "
set /P my_id="Please enter your ID: "
set /P my_pass="Please enter your Password: "

echo open %my_loc% > ftp_conn.txt
echo user %my_id% %my_pass%>> ftp_conn.txt
echo binary >> ftp_conn.txt
echo hash >> ftp_conn.txt
echo put %my_date%.zip >> ftp_conn.txt
echo close >> ftp_conn.txt
echo quit >> ftp_conn.txt

ftp -s:ftp_conn.txt

del ftp_conn.txt
del %my_date%.zip
--------------------------------------------

Jon
"Do or do not. There is no try!" - Yoda