how to use ADDEXCLUSION

Post here if you experience file transfer problems or unexpected errors.

how to use ADDEXCLUSION

Postby bruc3 » 30 Aug 2011, 16:10

Comment from the forum admin
The ADDEXCLUSION command is often missunderstood. If you stumble upon this thread I suggest you
to visit first the ADDEXCLUSION examples at:
http://www.scriptftp.com/reference.php?go=topic70


I'm attempting to use the ADDEXCLUSION command and it does not appear to work. Would like to avoid downloading files that are already in the target local directory. Here is how I am using it in my script. Any assistance you could provide is greatly appreciated. Thank you. -Bruce

ADDEXCLUSION(DOWNLOAD,"*.*","C:\landingzone")

Script output: :

OPENHOST("123.123.30.12","userhere","passwordhere")
Connecting to 123.123.30.12
Connected.

LOCALCHDIR("C:\landingzone")
Changing current local directory to C:\landingzone

ADDEXCLUSION(DOWNLOAD,"*.*","C:\landingzone")
Adding "*.*" at "C:\landingzone" to the download exclusion list.
GETLIST(REMOTE_FILES)
Getting file listing of current remote directory
Found 4 files.

GETFILE("08-24-2011-APNJ-DailyReminderReport.xls")
Downloading................. 08-24-2011-APNJ-DailyReminderReport.xls



ftp script iconFTP Script: (exclude.ftp) [ Download ] [ Hide ]
#
#
#-Go out to SSL secure remXchg site and get client uploaded files
#-which filenames begin with today's date every 30 minutes.
#
#
#-set log file
$logfile="C:\landingzone\logs\FTPGetFilesLOG-".GETDATE(FORMAT3).".txt"
LOGTO($logfile,APPEND)
PRINT("===============================================================================")
PRINT(GETDATE(FORMAT2))

#-connect to FTP server
OPENHOST("123.123.30.12","userhere","passwordhere")

#-set current local directory
LOCALCHDIR("C:\landingzone")

#-set filter for files that have already been downloaded
ADDEXCLUSION(DOWNLOAD,"*.*","C:\landingzone")

#-set current remote directory
CHDIR("/uploads")

#-set variable for todays date to match against
$todaysdate=(GETDATE(MONTH)."-".GETDATE(DAY)."-".GETDATE(YEAR))

#-get remote folder/directory list
GETLIST($remotefolders,REMOTE_DIRECTORIES)
FOREACH $item IN $remotefolders
  #-set the current remote directory
  CHDIR($item)
  #-get only files with filename starting with today's date
  GETLIST($remotefiles,REMOTE_FILES)
    FOREACH $item IN $remotefiles
    $fileprefix=TEXTCUT($item,1,10)
    IF($todaysdate==$fileprefix)
      GETFILE($item)
    END IF
  END FOREACH
  #-set the current remote directory back to /uploads/
  CHDIR("/uploads")
END FOREACH

#-clear exclusion list
CLEAREXCLUSION

#-get any/all files that may have been uploaded to the '/upload/' directory
GETFILE("*.*")

#-file transfer complete - close connection
CLOSEHOST

#-close the ScriptFTP window
#EXIT

 
bruc3
 
Posts: 2
Joined: 30 Aug 2011, 16:07

Re: how to use ADDEXCLUSION

Postby ScriptFTP support » 30 Aug 2011, 16:11

I think that the best way to do so is just use the SYNC command. It can be used to download only new or modified files. For example:

ftp script iconFTP Script: (sinchronize.ftp) [ Download ] [ Hide ]
# Download new and modified files from the remote
# folder /uploads to C:\landingzone
SYNC("C:\landingzone","/uploads",DOWNLOAD,SUBDIRS)


If you use ADDEXCLUSION this way:
ftp script iconFTP Script: [ Download ] [ Hide ]
ADDEXCLUSION(DOWNLOAD,"*.*","C:\landingzone")


you are excluding from download any remote file (*.*) that is in the directory C:\landingzone. Obviously this will make ADDEXCLUSION useless as no remote file has the path C:\landingzone (remote paths usually start with '/' instead)
ScriptFTP support
Site Admin
 
Posts: 624
Joined: 04 Aug 2008, 15:08
Location: Burgos, Spain, EU

Re: how to use ADDEXCLUSION

Postby bruc3 » 05 Sep 2011, 08:22

I ended up NOT using the ADDEXCLUSION command. I constructed multiple different loops for comparing the newly uploaded customer files to what was brought down locally. This runs every 30 minutes so I wanted to avoid downloading the same files over and over.

Attached is the final script so you can see and you are welcome to post it as I changed the names of the paths, passwords, etc.

Thanks again!


ftp script iconFTP Script: [ Download ] [ Hide ]
#
#
#-Go out to SSL secure site and get client uploaded files
#-which filenames begin with today's date every 30 minutes. If file
#-already exists in the local LandingZone directory then skip it.
#
#
#-set log file
$logfile="C:\landingzone\logs\FTPGetFilesLOG-".GETDATE(FORMAT3).".txt"
LOGTO($logfile,APPEND)
PRINT("===============================================================================")
PRINT(GETDATE(FORMAT2))

#-connect to FTP server
OPENHOST("ftp.secure.site.com","user","pwd")

#-set current local directory and build list of files in the LandingZone
LOCALCHDIR("C:\landingzone")
GETLIST($localfiles,LOCAL_FILES)
PRINT($localfiles)

#-set current remote directory
CHDIR("/uploads")

#-set all variables for todays date and file(s) to match against when looping files
$todaysdate=(GETDATE(MONTH)."-".GETDATE(DAY)."-".GETDATE(YEAR))
$ignorefile="FALSE"
$uploadedfiles="files:"

#-get remote folder/directory list
GETLIST($remotefolders,REMOTE_DIRECTORIES)
FOREACH $item IN $remotefolders
   #-set the current remote directory
   CHDIR($item)
   $clientdir=$item
   #-get list of files in remote directory
   GETLIST($remotefiles,REMOTE_FILES)
   FOREACH $item IN $remotefiles
      $remotefilename=$item
      $remotefileprefix=TEXTCUT($item,1,10)
      #-get only files with filename starting with today's date
      IF($todaysdate==$remotefileprefix)
         #-loop through all files already in the LandingZone directory
         FOREACH $item IN $localfiles
         $localfilename=$item
            #-same file already exists, set the ignorefile flag to true
            IF($remotefilename==$localfilename)
               $ignorefile="TRUE"
            END IF
         END FOREACH
         IF($ignorefile=="TRUE")
            #-skip it
         ELSE
            #-get the file into the local LandingZone directory
            GETFILE($remotefilename)
            #-build string variable for email message
            $uploadedfiles=$uploadedfiles.$todaysdate."-".$clientdir."-----"
         END IF
         #-set ignorefile flag back to the default of false
         $ignorefile="FALSE"
      END IF
   END FOREACH
   #-set the current remote directory back to /uploads/
   CHDIR("/uploads")
   $clientdir="UPLOAD"
END FOREACH

#-now get files that may have been uploaded to the /upload/ parent directory and add to email list
GETLIST($remoteparentfiles,REMOTE_FILES)
FOREACH $item IN $remoteparentfiles
   $remoteparentfilename=$item
   #-loop through all files already in the LandingZone directory
   FOREACH $item IN $localfiles
   $localfilename=$item
      #-same file already exists, set the ignorefile flag to true
      IF($remoteparentfilename==$localfilename)
         $ignorefile="TRUE"
      END IF
   END FOREACH
   IF($ignorefile=="TRUE")
      #-skip it
   ELSE
      #-get the file into the local LandingZone directory
      GETFILE($remoteparentfilename)
      $uploadedfiles=$uploadedfiles.$todaysdate."-".$clientdir."-----"
   END IF
END FOREACH

#-send email notification if at least 1 file was downloaded
If($uploadedfiles!="files:")
   $blat_path="C:\windows\system32\blat.exe"
   $smtp_svr="smtp.mysvr.com"
   $smtp_usr="support@mycompany.com"
   $smtp_pwd="mypwd"
   $email_from="support@remxchg.com"
   $email_to="me@mycompany.com"
   $email_subject="files_uploaded_from_clients"
   $email_body=$uploadedfiles
   $emailiT=$blat_path." -server ".$smtp_svr." -u ".$smtp_usr." -pw ".$smtp_pwd." -f ".$email_from." -to ".$email_to." -subject ".$email_subject." -body ".$email_body
   EXEC($emailit)
End IF

#-file transfer complete - close connection
CLOSEHOST

#-close the ScriptFTP window
EXIT
 
bruc3
 
Posts: 2
Joined: 30 Aug 2011, 16:07


Return to Troubleshooting



Who is online

Users browsing this forum: No registered users and 1 guest

cron