Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

cinder_bdt (1158)

cinder_bdt
  (email not shown publicly)

Journal of cinder_bdt (1158)

Friday December 28, 2001
02:06 PM

possibly helpful cmd file to ftp stuff

[ #1810 ]

So I don't always program in Perl. Once a week, we have to do this, and I don't want everyone who uses this labor-saving device to come back to me for maintenance. Therefore it was easier to write it in Windows NT CMD.

Here it is in case it might be useful to others:

@echo off
SETLOCAL :: Download weekly DAT files from NAI to current directory.

for /f "tokens=1" %%I in ('time /t') do set _TGT_TIME=%%I
for /f "tokens=2" %%I in ('date /t') do set _TGT_DATE=%%I

SET _DATVER=%1
SET /A _INCREMENTAL=_DATVER - 1

SET _LOGFILE=getdat.txt
SET _FTPSITE=proxy.mysite.com
SET _FTPDIR=/pub/antivirus/datfiles/4.x
SET _FTPPASS=me@mysite.com
SET _FTPUSER=anonymous@ftp.nai.com
SET _FTPCOMMANDS=ftpcmds.txt

echo.
echo Download weekly DAT files from NAI to current directory.
echo usage: %0 ^
echo where: ^ is a 4 digit number, for example 4178
echo.
echo Session logged to "%CD%\%_LOGFILE%".
echo press Ctrl-C now if you don't want to run this.
pause

echo Download in progress. ::first time writing to file, use only one arrow, to overwrite existing
echo open %_FTPSITE% > %_FTPCOMMANDS%
echo %_FTPUSER%>> %_FTPCOMMANDS%
echo %_FTPPASS% >> %_FTPCOMMANDS%

echo binary >> %_FTPCOMMANDS%

echo get %_FTPDIR%/delta.ini >> %_FTPCOMMANDS%
echo get %_FTPDIR%/update.ini >> %_FTPCOMMANDS%
echo get %_FTPDIR%/%_INCREMENTAL%%_DATVER%.upd >> %_FTPCOMMANDS%
echo get %_FTPDIR%/dat-%_DATVER%.tar >> %_FTPCOMMANDS%
echo get %_FTPDIR%/dat-%_DATVER%.zip >> %_FTPCOMMANDS%
echo get %_FTPDIR%/sdat%_DATVER%.exe >> %_FTPCOMMANDS%

echo close >> %_FTPCOMMANDS%
echo quit >> %_FTPCOMMANDS% ::first time writing to file, use only one arrow, to overwrite existing
echo. > "%_LOGFILE%"
echo %_TGT_TIME%, %_TGT_DATE% >> "%_LOGFILE%"
echo. >> "%_LOGFILE%"
echo %0 was called with %* >> "%_LOGFILE%"
echo. >> "%_LOGFILE%"
echo Input file: >> "%_LOGFILE%"
echo. >> "%_LOGFILE%"
type %_FTPCOMMANDS% >> "%_LOGFILE%"
echo. >> "%_LOGFILE%"
echo Generated activity: >> "%_LOGFILE%"
echo. >> "%_LOGFILE%" ::disable interactive prompting ::enable debugging ::use a command file ::redirect STDERR to STDOUT ::redirect STDOUT to append a log file
%SYSTEMROOT%\system32\ftp.exe -i -d -s:%_FTPCOMMANDS% >> "%_LOGFILE%" 2>&1
DEL %_FTPCOMMANDS%

echo Download complete.