FTP Upload only different file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Locked
Message
Author
sax
Posts: 2
Joined: 01 Feb 2010 15:32

FTP Upload only different file

#1 Post by sax » 01 Feb 2010 15:44

Hi I'd like to upload in a FTP folder only the file that are not present in my local folder.
I find this great script but this work in a different direction (it get the files that aren't present on my local folder) I tried to change the mget command wiht mput but doesn't work...

Anybody can help me THANK YOUUUUU !!

Bye
Andrea

here the script:

Code: Select all

@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 20081204 :$categories ReadFile
:$source http://www.dostips.com
SETLOCAL
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

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

Re: FTP Upload only different file

#2 Post by DosItHelp » 04 Feb 2010 22:10

sax,

Try this. I have done some testing. It also works for files with spaces in it.
Replace the section "Extract Ftp Script to download files..." with this:

Code: Select all

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"


A complete batch has been posted at http://www.dostips.com/DtTipsFtpBatchScript.php#Batch.FtpBatchUploadOnlyNewFiles

sax
Posts: 2
Joined: 01 Feb 2010 15:32

Re: FTP Upload only different file

#3 Post by sax » 05 Feb 2010 02:54

GREAT IT WORKS !!!!

MANY TANKS!!!

Andrea

Locked