| 1. |
Solve : check if file exist over ftp? |
|
Answer» I have a backup over FTP and sometimes happend backup didn't finished or even started. One way to do this would be to use the batch file to generate a temporary ftp script and use that to download the file, then check if it exists on the local machine. This would be a pretty bad approach though. It's likely that wget will download and create a zero byte file, but the filesize could then be tested - to see if it the correct filesize too.I have managed to delete zero bytes files on server so what I need is check if file is there if it is not than ftp backup should run again.http://www.dostips.com/DtTipsFtpBatchScript.php#Batch.FtpBatchUploadOnlyNewFiles Quote from: Squashman on February 19, 2015, 07:16:04 AM http://www.dostips.com/DtTipsFtpBatchScript.php#Batch.FtpBatchUploadOnlyNewFiles I see that script is in parts the same like I found out. but have no clue what should be in part REM the file was there, so do something Code: [Select]echo off :FETCHFILE ftp -s:ftp.txt IF EXIST filetocheckfor.txt ( REM the file was there, so do something ) ELSE echo Trying again... REM ping "sleep" would go here GOTO FETCHFILE )It is synching the FTP folder with your local folder! If the file does not exist on the FTP site but exists in the folder on your computer it will upload it.OK this is the script I try to SETUP folders to upload but not working, maybe I have set some settings wrong. Can someone please quick check of it and make some suggestions? Thank you. Code: [Select]Echo Off Setlocal Enabledelayedexpansion REM -- Define File Filter, i.e. files with extension .txt Set FindStrArgs=/E /D:"*.7z.*" 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 upload files that don't exist in remote folder Set "FtpCommand=mput" For %%A In (%FileList%) Do set "Exist["%%~A"]=Y" For /F "Delims=" %%A In ('"dir /b "%localdir%"|Findstr %FindStrArgs%"') Do ( If Not defined 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 184.50.15.14 username password !Title Preparing... cd /imagine_zip lcd D:\zipano_arhiv\imaginesql binary hash !Title Processing... %FtpCommand% %FtpCommand% !Title Disconnecting... disconnect bye and this are my ftp settings Code: [Select]open 184.50.15.14 username password status binary cd /imagine_zip lcd D:\zipano_arhiv\imaginesql mdelete *.7z.* mput "*.7z.*" quit del /Q D:\zipano_arhiv\imaginesql\*.* I get all the time this FINDSTR: Bad command line FINDSTR: Bad command line and don't know why scritp trying to connect http://www.dostips.comNo where in that code does it do any type of connection to DosTips.com Quote from: Squashman on February 28, 2015, 01:41:48 PM No where in that code does it do any type of connection to DosTips.comyou are right I checked again I maded a log from script it doesn't. But script still don't work First part looks like there is trouble searching file.can someone help me with this please? |
|