Windows Server 2008 - Calling FTP from .CMD - Pass a parameter to an FTP file?

Solution 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

Solution 2:

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.