handling_errors_1.ftp

This script uploads a set of files and does some error handling in the OPENHOST call.

It stores the result of OPENHOST in a variable and then compares its contents with “OK”. If it is different uses the GOTO command to make ScriptFTP jump to the top of the script and try to connect to the FTP server again.

# This is a label. It's used to mark a point in a script file.
:connect
 
# Connect to ftp.myhost.com and save the result in the variable
# result_open_host.
$result_open_host=OPENHOST("ftp.myhost.com","myuser","123456")
 
# If the content of result_open_host is different than
# "OK" means that the OPENHOST call failed
IF($result_open_host!="OK")
 # Show a message on the ScriptFTP window
 PRINT("Cannot connect!")
 
 # Wait 10 seconds
 SLEEP(10)
 
 # Show a message on the ScriptFTP window
 PRINT("Trying again")
 
 # Go to the label
 GOTO :connect
END IF
 
# If this point is reached means that ScriptFTP is
# connected
 
# Upload the files
PUTFILE("sales.xls")
PUTFILE("backup.zip")
PUTFILE("notes.txt")
PUTFILE("1.jpg")
 
# Close the connection 
CLOSEHOST