Automatically downloading files daily by psftp

R

Raven

Hi,

I am modifying my previous written batch file(though I am an amateur)
which can daily download a list of log files from a list of sftp
servers, which generates the logs daily. Since the previous script only
downloads ALL the files at night, which may cause certain problems as
the number of file in the servers get larger. I wish to write a batch
file that can get files generated yesterday (please note that log
filename follows the YYYYMMDD convention).

My previous operation is that I have a batch file which lists the
server and run psftp with another cmd for the software. My trouble now
is that the psftp seems not to support local system variable in their
wildcard.
(if yes, I can simply wirite psftp (e-mail address removed)....
cd ....
mget .../.../*%Dayvar%*)

previous operation:
Batch file(contain of list of server ips; psftp is called here) ->
psftp command file (contain the operation command for psftp)
end


So now I am thinking of another method. Could I generate one text file
by batch daily automatically before the downloading start which I can
specify the date. After psftp is fed with this file when it is called
by the batch file, it can seamlessly download all files in the server
whose names bear, say, 12?)

so my proposed operation:
batch file(generate a command file based on local system date for psftp
before the downloading start)->
batch file(contain of list of server ips; psftp is called here with the
newly created command file)
psftp does its job by running the newly created file
done

Thanks very much. And if you do know anyway of doing so, please let me
know.
 
F

foxidrive

So now I am thinking of another method. Could I generate one text file
by batch daily automatically before the downloading start which I can
specify the date. After psftp is fed with this file when it is called
by the batch file, it can seamlessly download all files in the server
whose names bear, say, 12?)

Using WSH to get yesterday's date (see below) and echoing the commands to a
script file, to pass on to PSFTP (which I know nothing about).
so my proposed operation:
batch file(generate a command file based on local system date for psftp
before the downloading start)->
batch file(contain of list of server ips; psftp is called here with the
newly created command file)
psftp does its job by running the newly created file
done

This code will get you yesterdays date in YYYYMMDD format.

@echo off
:: from code by Phil Robyn
setlocal
set date1=today
set qty=-1
if /i "%date1%" EQU "TODAY" (
set date1=now
) else (
set date1="%date1%"
)
echo >"%temp%\%~n0.vbs" s=DateAdd("d",%qty%,%date1%)
echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^&_
echo>>"%temp%\%~n0.vbs" right(100+month(s),2)^&_
echo>>"%temp%\%~n0.vbs" right(100+day(s),2)
for /f %%a in (
'cscript //nologo "%temp%\%~n0.vbs"') do set result=%%a
del "%temp%\%~n0.vbs"
endlocal& set day=%result:~0,4%%result:~4,2%%result:~6,2%
echo %%day%% is set to "%day%" (without the quotes)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top