upload_retry.ftp

This script uploads to the FTP server the files contained in the directory C:\SourceDir checking for each file if the upload is correctly done (retrieving the result of the PUTFILE command). If it fails retries the upload twice.

# Connect to FTP server
OPENHOST("192.168.0.32","myuser","123456")
 
# Change current local directory
LOCALCHDIR("c:\SourceDir")
 
# Retrieve file listing of
# the current local directory
GETLIST($filelist,LOCAL_FILES)
 
# For each file in the list
# do the following
FOREACH $file IN $filelist
 
 # try to upload the file
 $result=PUTFILE($file)
 
 # If failed try again
 IF($result!="OK")
     $result=PUTFILE($file)
 
     # if failed again reconnect
     # and try one more time
     IF($result!="OK")
         OPENHOST("192.168.0.32","myuser","123456")
         PUTFILE($file)
     END IF
 END IF
 
END FOREACH
 
 
# Close the connection
CLOSEHOST