# # Backup_advanced.ftp # # This script ZIPs a local directory and # uploads the created ZIP file to a FTP site. # It uses the free command-line tool Info-zip. # Download it at http://www.info-zip.org/ # # The ZIP filename is created based on the # current date. It also logs the script output # on a text file to check later if the backup has # been done correctly. # ------- Enter your own settings here -------- # FTP server ftp_server="127.0.0.1" ftp_user="carl" ftp_password="123456" # The local directory you need to backup backup_dir="C:\MyDir\" # The ZIP filename created from backup_dir zip_file_name_without_dot_zip="MyBackup" # The remote destination folder where # the ZIP file is uploaded remote_destination_folder="/" # A local temporary directory to # store the created ZIP file. local_temp_dir="C:\windows\temp" # The path of the free tool Info-zip # used to create the zip file info-zip_path="C:\infozip\" # The log file log_file="C:\backup_log.txt" #--------Script starts here -------------- current_date=GETDATE(FORMAT3) zip_file_name_with_date_and_extension=CONCAT(zip_file_name_without_dot_zip,"-",current_date,".zip") command_line=CONCAT(info-zip_path,"\zip.exe -r ",zip_file_name_with_date_and_extension," ",backup_dir) # Start logging LOGTO(log_file) # Go to the temp directory where the # ZIP file will be created LOCALCHDIR(local_temp_dir) # Run Info-zip archiver result=EXEC(command_line) # Check if the ZIP file was created IF(NOT(ISEQUAL(result,0))) PRINT("Error. The ZIP file could not be created. Closing ScriptFTP in 5 seconds") SLEEP(5) EXIT(result) END IF # Connect to FTP server result=OPENHOST(ftp_server,ftp_user,ftp_password) IF(NOT(ISEQUAL(result,"OK"))) PRINT("Error. Cannot connect to FTP server. Closing ScriptFTP in 5 seconds") SLEEP(5) EXIT(result) END IF # Change current remote dir to the # destination dir result=CHDIR(remote_destination_folder) IF(NOT(ISEQUAL(result,"OK"))) PRINT("Error. Cannot go to remote destination dir. Closing ScriptFTP in 5 seconds") SLEEP(5) CLOSEHOST EXIT(result) END IF result=PUTFILE(zip_file_name_with_date_and_extension) IF(NOT(ISEQUAL(result,"OK"))) PRINT("Error. Cannot upload the ZIP file. Closing ScriptFTP in 5 seconds") SLEEP(5) CLOSEHOST EXIT(result) END IF CLOSEHOST #delete the zip file command_line2=CONCAT("del /Q ",zip_file_name_with_date_and_extension) EXEC(command_line2) PRINT("Backup finished. Closing ScriptFTP in 5 seconds.") SLEEP(5) EXIT(0)