Script

FTP

The professional tool to automate FTP, SFTP, FTPS

and schedule FTP batch jobs

update_web_advanced.ftp

This script updates a web site from a local directory.
It’s a more complex version of the example update_web.ftp. I tries connecting three times and if all the attempts failed it shows a message and close ScriptFTP.

# Write your own settings here:
$webserver="127.0.0.1"
$myuser="carl"
$mypassword="123456"
$LocalWebFolder="C:\WebFiles"
$RemoteWebFolder="/www"
 
 
 
 
# Set the connection attempts counter to 1
$connection_attempt=1
 
# We will jump here to retry the connection
:connect
 
# Connect to the web server
$result_open_host=OPENHOST($webserver,$myuser,$mypassword)
 
# Check if OPENHOST failed
IF($result_open_host!="OK")
 IF($connection_attempt<3)
 # Increment the connection counter
 $connection_attempt=$connection_attempt+1
 
 PRINT("Trying again. Attempt number ".$connection_attempt." of 3")
 
 # Try again
 GOTO :connect
 ELSE
 # Reached the three attempts limit
 # Jump to the failed_connection label
 GOTO :failed_connection 
 END IF
END IF
 
 
# If ScriptFTP reaches this point means that it's connected
# to the webserver.
PRINT("_____Uploading modified files______")
 
# Upload new or modified files. Ignore subdirectories.
$result_upload=SYNC($LocalWebFolder,$RemoteWebFolder,UPLOAD)
 
# Check if SYNC failed
IF($result_upload!="OK")
 # Jump to failed_put
 GOTO :failed_sync
END IF
 
 
PRINT("Files uploaded succesfully")
 
# Close the connection
CLOSEHOST()
 
# Stop the script execution
STOP 
 
# Go here when something with the upload is wrong
:failed_sync
PRINT("Error uploading files")
CLOSEHOST()
STOP
 
 
# Go here when the connection failed three times 
:failed_connection
PRINT("Cannot connect to the FTP server.")
STOP