WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

WinInet
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

iFtpGet Newer Files Only


;UNDEBUGGED - Use at your own risk
AddExtender("WWINT44I.DLL")
ftpserver = "ftp.windowware.com"
uid = "anonymous"
pswd = "anonymous"
ftpdir = "wwwftp/wb01/"
localdir = "c:\temp\FTP_Test\"  
filetype = "*.pdf" ;GET ONLY PDF FILES!!!!!!!!!!!

If !DirExist(localdir) then DirMake(localdir)

;initalize variables
tophandle=iBegin(0,"","")
conhandle=iHostConnect(tophandle,ftpserver,@FTP, uid,pswd)
if conhandle==0
   message("ERROR","Unable to connect to host")
   exit
endif

handle=iFtpFindInit(conhandle,ftpdir,filetype,@False,@False) 
if handle==0
   message("ERROR","iFtpFindInit FAILED")
   ;Free handles
   iClose(conhandle)
   iClose(tophandle)
   exit
endif

While 1
   ftpfiledata = iFtpFindNext(@True)
   if ftpfiledata=="" 
      break
   endif
   ftpfilename = itemextract(1,ftpfiledata,@Tab)
   ftplastwrite =  itemextract(6,ftpfiledata,@Tab);extracts last write time
   targfilename=Filemapname(ftpfilename,localdir)

   ;Check if file exists in local directory
   lochandle=iLocFindInit(localdir,ftpfilename,@FALSE)
   if !lochandle
      ;File doesn't exist locally so FTP GET the file
      iFtpGet(conhandle,ftpfilename,targfilename,0,@BINARY, @TRUE)
      if getfile==0  
         message("iFtpGet Failed",StrCat("File ",ftpfilename, @Crlf, "iGetLastError ",iGetLastError(),@Crlf,"iGetResponse ",iGetResponse())
         ;Free handles
         iClose(handle)
         iClose(conhandle)
         iClose(tophandle)
         exit
      endif 
      continue ; move to next file
   endif   

   ;File exists locally then check date
   localfile=iLocFindNext(@true)
   locfilename = itemextract(1,ftpfiledata,@Tab)
   loclastwrite =  itemextract(6,ftpfiledata,@Tab);extracts last write time

   ;iFTPGET the remote file if local file is older or same data as FTP file
   ;if loclastwrite <= ftplastwrite 
   ;
   ;or
   ;
   ;iFTPGET the remote file ONLY if local file is older
   if loclastwrite < ftplastwrite 
      getfile = iFtpGet(conhandle,ftpfilename,targfilename,0,@BINARY, @TRUE)
      if getfile==0  
         message("iFtpGet Failed",StrCat("File ",ftpfilename, @Crlf, "iGetLastError ",iGetLastError(),@Crlf,"iGetResponse ",iGetResponse())
         ;Free handles
         iClose(handle)
         iClose(conhandle)
         iClose(tophandle)
         exit
      endif 
    endif  
 
    iClose(lochandle)
Endwhile

iClose(handle)
iClose(conhandle)
iClose(tophandle)
exit 

Article ID:   W16890
File Created: 2017:07:28:12:58:47
Last Updated: 2007:07:03:13:26:43