5

I am calling the following from a .cmd file:

 ftp -d -s:D:\backup\web-daily.txt

The web-daily.txt file is an ftp input file with similar contents to this:

open <server>
<login>
<password>
put d:\backup\web-daily.7z web-daily.7z
quit

I need to be able to pass the current date to the ftp input file. Is this doable without having to execute a program that actually modifies web-daily.txt? This is because web-daily.7z is actually web-daily_%date:~10,4%%date:~4,2%%date:~7,2%.7z (or web-daily_yyyy_MM_dd.7z).

I'd like to pass this date in as a parameter if possible.

Brian Webster
  • 1,123
  • 1
  • 18
  • 39

3 Answers3

1

Here's how to effectively pass a date parameter to an FTP input file on windows.

@echo off
setlocal

@echo off > %0.ftp
>> %0.ftp echo open <server>
>> %0.ftp echo <user>
>> %0.ftp echo <pw>
>> %0.ftp echo put d:\backup\web-daily_%date:~10,4%_%date:~4,2%_%date:~7,2%.7z web-daily_%date:~10,4%_%date:~4,2%_%date:~7,2%.7z
>> %0.ftp echo quit

ftp -s:%0.ftp

This will send web-daily_yyyy_mm_dd.7z to the ftp server.

Brian Webster
  • 1,123
  • 1
  • 18
  • 39
  • 1
    Only works in your locale. For me `_-0_-2` is inserted in place of the date. Be very careful with dates in batch files. – Joey Feb 21 '10 at 11:59
  • Does %date% give you something more meaningful? It may have to be parsed differently. – Brian Webster Feb 21 '10 at 17:56
1

I agree, this will do it, in North American format. There may be a way to make it universal, but that may not be important if the server won't change.

@echo off
setlocal

@echo off > %0.ftp
>> %0.ftp echo open <server>
>> %0.ftp echo <user>
>> %0.ftp echo <pw>
>> %0.ftp echo put d:\backup\web-daily_%date:~10,4%_%date:~4,2%_%date:~7,2%.7z web-daily_%date:~10,4%_%date:~4,2%_%date:~7,2%.7z
>> %0.ftp echo quit

ftp -s:%0.ftp
xpda
  • 151
  • 2
  • 10
-2
Rem: This worked for me

@echo off
setlocal

@echo off > %0.ftp
>> %0.ftp echo open **server**
>> %0.ftp echo **userid**
>> %0.ftp echo **password**
>> %0.ftp hash
>> %0.ftp asc
>> %0.ftp echo lcd c:\program\data\ (your local path)
>> %0.ftp echo cd fam/user/tcs/in/hold (your ftp path)
>> %0.ftp echo get 01000%date:~10,4%%date:~4,2%%date:~7,2%01.txt
>> %0.ftp echo quit

ftp -s:%0.ftp
del %0.ftp

rem below line gets a file with today's date from the ftp server
01000%date:~10,4%%date:~4,2%%date:~7,2%01.txt