2013-09-24 6 views
0

예약 된 Windows 서비스에서 5 분마다 실행하는 배치 파일이 있습니다. 배치 파일은 특정 파일 마스크 인 * .ext에 대해 mget을 실행합니다. mget 이후에 mdel * .ext가 수행됩니다. 최근에 문제가 발생했습니다 : 파일 z.ext가 mget과 mdel 실행 사이에 생성되면 해당 파일은 삭제되지만 mget에는 없었습니다. 어느 것이 코스에서 의미가 있습니다. 그래서 지금은 파일을 통해 반복하고 mget 및 mdel 파일을 파일별로 적절한 Windows ftp 명령을 찾고 있습니다. 그게 가능합니까?bat 파일을 사용하여 FTP 디렉토리의 파일을 반복합니다.

답변

1

ftp scriptng은 매우 제한되어 있지만, this approach을 사용할 수 있다고 생각합니다. 기본적으로 ftp를 두 번 실행해야 다운로드 할 파일 목록을 수집 한 다음 두 번째로 각 파일을 다운로드하고 삭제할 수 있습니다 (많은 cmd 스크립팅과 함께). 오류 처리 및 FTP 서버는 오류 허용 오차로 정확하게 알려져 있지 않습니다.

위의 웹 사이트에서 관련 예는 다음과 같습니다

@Echo Off 

REM -- Define File Filter, i.e. files with extension .txt 
Set FindStrArgs=/E /C:".txt" 

REM -- Extract Ftp Script to create List of Files 
Set "FtpCommand=ls" 
Call:extractFileSection "[Ftp Script 1]" "-">"%temp%\%~n0.ftp" 
Rem Notepad "%temp%\%~n0.ftp" 

REM -- Execute Ftp Script, collect File Names 
Set "FileList=" 
For /F "Delims=" %%A In ('"Ftp -v -i -s:"%temp%\%~n0.ftp"|Findstr %FindStrArgs%"') Do (
    Call Set "FileList=%%FileList%% "%%A"" 
) 

REM -- Extract Ftp Script to download files that don't exist in local folder 
Set "FtpCommand=mget" 
For %%A In (%FileList%) Do If Not Exist "%%~A" Call Set "FtpCommand=%%FtpCommand%% "%%~A"" 
Call:extractFileSection "[Ftp Script 1]" "-">"%temp%\%~n0.ftp" 
Rem Notepad "%temp%\%~n0.ftp" 

For %%A In (%FtpCommand%) Do Echo.%%A 

REM -- Execute Ftp Script, download files 
ftp -i -s:"%temp%\%~n0.ftp" 
Del "%temp%\%~n0.ftp" 
GOTO:EOF 


:extractFileSection StartMark EndMark FileName -- extract a section of file that is defined by a start and end mark 
::     -- [IN]  StartMark - start mark, use '...:S' mark to allow variable substitution 
::     -- [IN,OPT] EndMark - optional end mark, default is first empty line 
::     -- [IN,OPT] FileName - optional source file, default is THIS file 
:$created 20080219 :$changed 20100205 :$categories ReadFile 
:$source http://www.dostips.com 
SETLOCAL Disabledelayedexpansion 
set "bmk=%~1" 
set "emk=%~2" 
set "src=%~3" 
set "bExtr=" 
set "bSubs=" 
if "%src%"=="" set src=%~f0&  rem if no source file then assume THIS file 
for /f "tokens=1,* delims=]" %%A in ('find /n /v "" "%src%"') do (
    if /i "%%B"=="%emk%" set "bExtr="&set "bSubs=" 
    if defined bExtr if defined bSubs (call echo.%%B) ELSE (echo.%%B) 
    if /i "%%B"=="%bmk%" set "bExtr=Y" 
    if /i "%%B"=="%bmk%:S" set "bExtr=Y"&set "bSubs=Y" 
) 
EXIT /b 


[Ftp Script 1]:S 
!Title Connecting... 
open example.com 
username 
password 

!Title Preparing... 
cd public_html/MyRemoteDirectory 
lcd c:\MyLocalDirectory 
binary 
hash 

!Title Processing... %FtpCommand% 
%FtpCommand% 

!Title Disconnecting... 
disconnect 
bye 
아마

더 나은 파이썬 또는 다른 스크립트 환경에서 그것을 단지에 (당신이 배포 문제가없는 가정.)

관련 문제