# # This script syncronizes a remote folder from # a local directory and sends an email if an error # is found. The log file is also sent attached. # # This script uses the free command-line tool Blat # http://www.blat.net. # # A different error email is sent depending on # the error found # Log file log_file_path="C:\windows\temp\logfile.txt" LOGTO(log_file_path) # FTP server settings ftp_server="ftp.myserver.com" ftp_user="myuser" ftp_password="myserver" # Blat parameters blat_path="C:\blat\blat.exe" smtp_server="smtp.myserver.com" smtp_user="myuser_at_myserver.com" smtp_password="mypassword" email_from="scriptftp@myserver.com" email_to="me@myserver" email_subject="ScriptFTP error message" email_body1="Could not connect to FTP server" email_body2="Could not syncronize files" # Construct the blat command line. Note that the following lines are very long and # your editor may have cutted it. A ScriptFTP command must be contained in only one line. blat_cmd_line1=CONCAT(blat_path," -server ",smtp_server," -u ",smtp_user," -pw ",smtp_password," -f ",email_from," -to ",email_to," -subject ",QUOTE,email_subject,QUOTE," -body ",QUOTE,email_body1,QUOTE," -ps ",QUOTE,log_file_path,QUOTE) blat_cmd_line2=CONCAT(blat_path," -server ",smtp_server," -u ",smtp_user," -pw ",smtp_password," -f ",email_from," -to ",email_to," -subject ",QUOTE,email_subject,QUOTE," -body ",QUOTE,email_body2,QUOTE," -ps ",QUOTE,log_file_path,QUOTE) result=OPENHOST(ftp_server,ftp_user,ftp_password) IF(NOT(ISEQUAL(result,"OK"))) PRINT("Cannot connect to FTP server. Sending an email and aborting in 5 seconds.") EXEC(blat_cmd_line1) SLEEP(5) EXIT(1) END IF result=SYNC("c:\docs_dir","/every_day_saved_docs",UPLOAD) IF(NOT(ISEQUAL(result,"OK"))) PRINT("Cannot syncronize. Sending an email and aborting in 5 seconds.") EXEC(blat_cmd_line2) SLEEP(5) EXIT(2) END IF CLOSEHOST EXIT(0)