Script

FTP

The professional tool to automate FTP, SFTP, FTPS

and schedule FTP batch jobs

upload_and_delete.ftp

 

This script uploads every xml file in C:\pim\outbox and deletes it once the file is successfully uploaded. It checks if the file was successfully uploaded before deleting it from C:\pim\outbox. Note the use of the FOREACH loop for this purpose.

This is real customer case. A FTP server located in the local network were used to store xml files awaiting to be processed. ScriptFTP was set to run every five minutes in the computers where the xml files were generated.

# Connect to the FTP server
OPENHOST("192.168.23.32","myusername","mypassword")
 
# Change working directory to C:\pim\outbox
LOCALCHDIR("C:\pim\outbox")
 
# Retrieve the C:\pim\outbox file listing
$result=GETLIST($list,LOCAL_FILES,"*.xml")
 
# If GETLIST failed stop the script
IF($result!="OK")
 STOP
END IF
 
# For each file in $list...
FOREACH $item IN $list
 # Upload the file
 $result=PUTFILE($item)
 # If the file has been succesfully uploaded
 # delete the local copy of the file
 IF($result=="OK")
 EXEC("del ".$item)
 END IF
END FOREACH
 
 
CLOSEHOST