echo off

rem Script: getrmanfiles.bat
rem Author: Theodore Zacharia
rem Version: 1.0
rem Date: 12/03/2010
rem A DOS (yuk) script to enable getting files off a UNIX server when we think
rem a problem / disconnection / timeout is highly likely and you need to re-start
rem at some known point.

set DESTDIR="d:\scrx\rman"
set RMTIP="10.96.xxx.xx"
set RMTUSER="oracle"
set RMTDIR="/u02/DONOTDELETE"
set FLIST="flist.txt"
set USEFLIST="n"

set /p PASSWORD="password "
cls

:CHECKRS 
IF "%1%"=="" GOTO ALLFILES 
set RESTART=%1% 
set DOCP=0 
echo Looking for a restart at %RESTART% 
goto STARTJOB

:ALLFILES 
set RESTART="" 
set DOCP=1 

rem If you are asking for a restart, you don't get the option to re-download the flist
IF NOT "%1%" == "" GOTO restart


rem First get list of files file, on remote server do
rem if one already exits, ask if to get
IF NOT EXIST %FLIST% GOTO getflist
set /p USEFLIST="The file %FLIST exists, shall we use this copy (y/n)"
IF "%USEFLIST%" == "n" GOTO getflist
goto STARTJOB


:getflist
echo "getting file from %RMTDIR%"
pscp -pw %PASSWORD% %RMTUSER%@%RMTIP%:%RMTDIR%/%FLIST% .
goto STARTJOB

:restart
echo "Restarting from file %1%"

rem Now process the files, restarting if necessary
:STARTJOB

for /f %%a IN ('type %FLIST%') do call :copyafile %%a 
goto end 

:copyafile
IF "%1"=="%RESTART%" set DOCP=1 
IF %DOCP%==1 GOTO docopy 
echo skipping %1 
goto end 

:docopy 
echo copying %1 
pscp -pw %PASSWORD% %RMTUSER%@%RMTIP%:%RMTDIR%/%1 %DESTDIR%
goto end 


goto end



:end