Script

FTP

The professional tool to automate FTP, SFTP, FTPS

and schedule FTP batch jobs

goto_and_stop.ftp

This script downloads files from the FTP server and checks the returned value from every command. If an error is found uses the GOTO command to jump to other part of the script and stops ScriptFTP.

# Connect to FTP server
$result=OPENHOST("127.0.0.1","carlos","123456")
 
# If result is different than OK jump to :failed_connection
IF($result!="OK")
 GOTO :failed_connection
END IF
 
 
# Change current local directory
$result=LOCALCHDIR("C:\destination_dir")
IF($result!="OK")
 GOTO :failed_change_local_dir
END IF
 
 
# Download all the files and subdirectories to C:\destination_dir
$result=GETFILE("*.*",SUBDIRS)
 
# If result is different than OK jump to :failed_transfer
IF($result!="OK")
 GOTO :failed_transfer
END IF
 
# Transfer finished, close the connection
CLOSEHOST
 
# Done. Stop the script execution.
STOP
 
 
# Go here when the connection failed three times 
:failed_connection
PRINT("Cannot connect to the FTP server. Stopping script execution.")
STOP
 
# Go here when got transfer errors 
:failed_transfer
PRINT("Error downloading files.Stopping script execution.")
STOP
 
 
# Go here when got transfer errors 
:failed_change_local_dir
PRINT("Cannot access C:\destination_dir. Stopping script execution.")
STOP