The professional tool to automate FTP and secure FTP transfers    
Automated FTP & Batch FTP    


Examples of the old version (1.4) 

Simple FTP Scripts:

simple_upload.ftp [View] [Download] Upload a set of files to the FTP server.
simple_download.ftp [View] [Download] Download a set of files to the FTP server.
sync_local_dir.ftp [View] [Download] Download the new and modified files from the FTP sever.
backup.ftp [View] [Download] Upload a local directory to the FTP server.
update_web.ftp [View] [Download] Upload the modified files to the web server
get_last_pricelist.ftp [View] [Download] Download two files from the FTP server.


Advanced FTP Scripts:

upload_retry.ftp [View] [Download] Upload a set of files to the FTP server. Retry to connect to the server if connection failed.
backup_advanced.ftp [View] [Download] This script ZIPs a local directory and uploads the generated ZIP file to the FTP site. It handles unexpected errors and logs the transfer on a text file.
send_mail.ftp [View] [Download] This script syncronizes a remote folder from a local directory and sends an email if an error is found. It also attached a log file to the email.
update_web_advanced.ftp [View] [Download] Update a web from a local directory. It handles the errors that may generate OPENHOST and PUTFILE.
always_syncing.ftp [View] [Download] This script does an infinite loop and mantains a local dir always syncronized with a FTP site:
downloadwww.ftp [View] [Download] Connect to a web server and download all the files inside the www folder.
server_sync.ftp [View] [Download] This script syncs two FTP servers every hour
extreme_script.ftp [View] [Download] This is a very advanced script submited by Extreme Solutions. It makes backups of remote sites and receives the server address, user name, password and remote directory as command line parameters (See GETPARAM). It also has a nice error handling and it's capable of sending reports via email.














simple_upload.ftp
Download
#
# simple_upload.ftp
# upload a set of files to the FTP server
#


OPENHOST("ftp.myhost.com","myuser","123456")

# upload the files
PUTFILE("sales.xls")
PUTFILE("backup.zip")
PUTFILE("notes.txt")
PUTFILE("1.jpg")

CLOSEHOST()





simple_download.ftp
Download
#
# simple_download.ftp
# Download a set of files to the FTP server
#


OPENHOST("ftp.myhost.com","myuser","123456")

# download the files
GETFILE("sales.xls")
GETFILE("backup.zip")
GETFILE("notes.txt")
GETFILE("*.jpg")

CLOSEHOST()





sync_local_dir.ftp
Download
#
# sync_local_dir.ftp
# Syncronize a local directory from a remote folder
#

OPENHOST("ftp.myhost.com","myuser","123456")

# Download the modified and new files from the FTP server
# to c:\mydir. Subdirectories included
SYNC("C:\MyDir","/",DOWNLOAD,SUBDIRS)

CLOSEHOST()





backup.ftp
Download
#
# This backup script runs every day at 3 AM.
# 172.16.0.4 is the office backup sever.
#

OPENHOST("172.16.0.4","carl","123456")
CHDIR("MyBackupRemoteDir")
LOCALCHDIR("C:\My Documents")

# Put all files
PUTFILE("*.*",SUBDIRS)

CLOSEHOST






update_web.ftp
Download
#
# Web Server update example
#
# Uploads the modified files to the web server
#

# Write your settings here:
hostname="ftp.host.com"
user="myuser"
password="mypassword"

OPENHOST(hostname,user,password)
SYNC("C:\LocalWebFolder\","/www",UPLOAD)
CLOSEHOST()






get_last_pricelist.ftp
Download
# Get the last version of the price list from the central office
# Placing this file on the startup folder the shop computer will
# execute this script when is switched on in the morning
# 80.37.175.183 is the central office server

OPENHOST("80.37.175.183")
CHDIR("/pub/documents_distribution/")
GETFILE("price_list.xls")
GETFILE("price_list.doc")
CLOSEHOST
EXIT





upload_retry.ftp
Download
#
# upload_retry.ftp
# upload a set of files to the FTP server
# Retry to connect to the server if connection failed

:connect
result_open_host=OPENHOST("ftp.myhost.com","myuser","123456")
IF(NOT(ISEQUAL(result_open_host,"OK")))
      PRINT("Cannot connect! Trying again.")
      # Wait 10 seconds and try again
      SLEEP(10)
      GOTO connect
END IF

# upload the files
PUTFILE("sales.xls")
PUTFILE("backup.zip")
PUTFILE("notes.txt")
PUTFILE("1.jpg")

CLOSEHOST()






backup_advanced.ftp
Download
#
# Backup_advanced.ftp
#
# This script ZIPs a local directory and
# upload 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)






send_mail.ftp
Download
#
# This script syncronizes a remote folder from
# a local directory and sends an email if an error
# is found. The log file is also sent attached.
#
# This script uses the free command-line tool Blat
# http://www.blat.net.
#
# A different error email is sent depending on
# the error found


# Log file
log_file_path="C:\windows\temp\logfile.txt"
LOGTO(log_file_path)


# FTP server settings

ftp_server="ftp.myserver.com"
ftp_user="myuser"
ftp_password="myserver"

# Blat parameters
blat_path="C:\blat\blat.exe"

smtp_server="smtp.myserver.com"
smtp_user="myuser_at_myserver.com"
smtp_password="mypassword"

email_from="scriptftp@myserver.com"
email_to="me@myserver"
email_subject="ScriptFTP error message"
email_body1="Could not connect to FTP server"
email_body2="Could not syncronize files"



# Construct the blat command line. Note that the following lines are very long and
# your editor may have cutted it. A ScriptFTP command must be contained in only one line.
blat_cmd_line1=CONCAT(blat_path," -server ",smtp_server," -u ",smtp_user," -pw ",smtp_password," -f ",email_from," -to ",email_to," -subject ",QUOTE,email_subject,QUOTE," -body ",QUOTE,email_body1,QUOTE," -ps ",QUOTE,log_file_path,QUOTE)
blat_cmd_line2=CONCAT(blat_path," -server ",smtp_server," -u ",smtp_user," -pw ",smtp_password," -f ",email_from," -to ",email_to," -subject ",QUOTE,email_subject,QUOTE," -body ",QUOTE,email_body2,QUOTE," -ps ",QUOTE,log_file_path,QUOTE)





result=OPENHOST(ftp_server,ftp_user,ftp_password)
IF(NOT(ISEQUAL(result,"OK")))
      PRINT("Cannot connect to FTP server. Sending an email and aborting in 5 seconds.")
      EXEC(blat_cmd_line1)
      SLEEP(5)
      EXIT(1)
END IF

result=SYNC("c:\docs_dir","/every_day_saved_docs",UPLOAD)
IF(NOT(ISEQUAL(result,"OK")))
      PRINT("Cannot syncronize. Sending an email and aborting in 5 seconds.")
      EXEC(blat_cmd_line2)
      SLEEP(5)
      EXIT(2)
END IF
CLOSEHOST
EXIT(0)









update_web_advanced.ftp
Download
#
# ___ Web server update advanced ___
#
# Updates a web from a local directory.
# OPENHOST and SYNC error handling.

webserver="ftp.host.com"
myuser="joe"
mypassword="123456"

LocalWebFolder="C:\WebFiles"


# Only show errors, transfered files and print messages
SILENT(ON)

# Try to connect three times.
attempts="1"
:connect
PRINT("_____Connecting_____")
result_open_host=OPENHOST(webserver,myuser,mypassword)
IF(NOT(ISEQUAL(result_open_host,"OK")))
      PRINT("Cannot connect! Trying again.")
      IF(ISEQUAL(attempts,"3"))
            GOTO failed_connection
      ELSE
            attempts=ADD(attempts,"1")
            SLEEP("3")
            GOTO connect
      END IF
END IF



PRINT("_____Uploading modified files______")

result_upload=SYNC(LocalWebFolder,"/www",UPLOAD)
IF(NOT(ISEQUAL(result_put,"OK")))
      PRINT("Error uploading files")
      GOTO failed_put
END IF



PRINT("Files uploaded succesfully")
CLOSEHOST()
SLEEP("60")
EXIT


:failed_put
PRINT("An Error was found while putting files")
CLOSEHOST()
SLEEP("60")
EXIT

:failed_connection
PRINT("Cannot connect to remote host")
SLEEP("60")
EXIT









always_syncing.ftp
Download
#This script does an infinite loop and mantains a local dir always syncronized from a FTP site
host="172.16.0.4"
user="carl"
password="123456"



openhost(host,user,password)
chdir("remotedir/remotesubdir")
localchdir("C:\localdir\")

#do an infinite loop
while("TRUE")
      result=sync("C:\local_dir","/myremotedir",DOWNLOAD)
      if(not(isequal(result,"OK")))
            print("ERROR on SYNC, exiting")
            #exit with error code 1
            sleep("10")
            exit("1")
      else
            print("All files downloaded. Waiting 10 seconds")
            sleep("10")
      end if
end while






downloadwww.ftp
Download
#Connect to ftp.myhost.com and download all the files inside the www folder.
#define some variables
host="ftp.myhost.com"
user="carl"
password="1234567890"

#this is a label, used by the GOTO command
:start
#connect to FTP server
result=openhost(host,user,password)

#check what happened with ftpopenhost
if(isequal(result,"OK"))
       print("CONNECTED")
else
      print("Cannot connect. Wait 5 seconds and try again")
      sleep("5")
      goto start
end if

#do the stuff
localchdir("C:\localwww\")
chdir("www")
getfile("*.*")

closehost()
print("FINISHED")
exit






server_sync.ftp
Download
#This script syncs two FTP servers every hour.
#It does an infinite loop, no scheduling needed.

master_server="ftp.scriptftp.com"
master_server_user="myuser"
master_server_passwd="mypass"

slave_server="172.16.0.4"
slave_server_user="carl"
slave_server_passwd="123456"



:START

result=OPENHOST(master_server,master_server_user,master_server_passwd)
if(not(isequal(result,"OK")))
     print("Cannot connect to master server, aborting")
     Sleep("2")
     exit("1")
end if



LOCALMKDIR("C:\TEMP")
result=LOCALCHDIR("C:\TEMP")



if(not(isequal(result,"OK")))
     print("Cannot access local TEMP dir, aborting")
     Sleep("2")
     exit("1")
end if

GETFILE("*.html",SUBDIRS)
CLOSEHOST

#Go to slave server, where a copy of master server resides

result=OPENHOST(slave_server,slave_server_user,slave_server_passwd)

if(not(isequal(result,"OK")))
     print("Cannot connect to slave server, aborting")
     Sleep("2")
     exit("1")
end if
PUTFILE("*.*",SUBDIRS)

CLOSEHOST

#Now it's time to remove C:\temp.
#Warning: Dangerous code.
#EXEC("del /S *.*")
#localchdir("..")
#localrmdir("TEMP")

#Wait for an hour and sync the servers again
Sleep("3600")
goto START






extreme_script.ftp
Download
# Only show errors, transfered files and print messages
SILENT(ON)
# Passive mode utilized because I am behind a firewall
SETPASSIVE(ENABLED)

# Retrieve the FTP server information from the command line
ftp_customername=GETPARAM(3)
ftp_server=GETPARAM(4)
ftp_user=GETPARAM(5)
ftp_password=GETPARAM(6)
ftp_remotepath=GETPARAM(7)
ftp_ignoredirectory=GETPARAM(8)

PRINT ("Running script...")

# ******************************************************
# This script uses the free command-line emailer Blat
# to report reults via email.
# http://www.blat.net.
#*******************************************************
# Blat parameters
blat_path="C:\windows\system32\blat.exe"

smtp_server="smtp.isp.com"


email_from="scriptftp@yourdomain.com"
email_to="webmaster@yourdomain.com"


email_subject1=CONCAT("*ERROR in ScriptFTP for ",ftp_customername)
email_subject2=CONCAT("Success for ",ftp_customername," ScriptFTP")

#subject 3 defined further with error message below
#email_subject3=CONCAT("**ERROR, retrying ScriptFTP for ",ftp_customername)

email_body1="Could not connect to FTP server."
email_body2="Could not synchronize files."
email_body3="Directory didn't exist, created new one."
email_body4=CONCAT(ftp_customername," FTP Successful! ")
email_body5="Parameter missing."
email_body6="Retrying synchronization..."


#Get Date YYYYMMDD
current_date=GETDATE(FORMAT1)
#Set Log File Path
LogFile=CONCAT("C:\Windows\temp\",ftp_customername,"-",current_date,".txt")
# Log transfer on a text file
LOGTO(LogFile)

# Construct the blat command line.
# Note that the following lines are very long and
# your editor may have cutted it. A ScriptFTP
# command must be contained in only one line.
#
# Smtp authentication disbled in this example.
# Send log as an attachment
blat_cmd_line1=CONCAT(blat_path," -server ",smtp_server," -f ",email_from,"-to ",email_to," -subject ",QUOTE,email_subject1,QUOTE," -body",QUOTE,email_body1,QUOTE," -ps ",QUOTE,LogFile,QUOTE)
blat_cmd_line2=CONCAT(blat_path," -server ",smtp_server," -f ",email_from,"-to ",email_to," -subject ",QUOTE,email_subject1,QUOTE," -body",QUOTE,email_body2,QUOTE," -ps ",QUOTE,LogFile,QUOTE)
blat_cmd_line3=CONCAT(blat_path," -server ",smtp_server," -f ",email_from,"-to ",email_to," -subject ",QUOTE,email_subject1,QUOTE," -body",QUOTE,email_body3,QUOTE," -ps ",QUOTE,LogFile,QUOTE)
blat_cmd_line4=CONCAT(blat_path," -server ",smtp_server," -f ",email_from,"-to ",email_to," -subject ",QUOTE,email_subject2,QUOTE," -body",QUOTE,email_body4,QUOTE," -ps ",QUOTE,LogFile,QUOTE)
blat_cmd_line5=CONCAT(blat_path," -server ",smtp_server," -f ",email_from,"-to ",email_to," -subject ",QUOTE,email_subject1,QUOTE," -body",QUOTE,email_body5,QUOTE," -ps ",QUOTE,LogFile,QUOTE)
blat_cmd_line6=CONCAT(blat_path," -server ",smtp_server," -f ",email_from,"-to ",email_to," -subject ",QUOTE,email_subject3,QUOTE," -body",QUOTE,email_body6,QUOTE," -ps ")

#test Parameters
IF(ISEQUAL(ftp_customername,""))
     PRINT("Missing Parameter #1, customername, exiting.")
     GOTO failed_parameter
END IF
IF(ISEQUAL(ftp_server,""))
     PRINT("Missing Parameter #2, server, exiting.")
     GOTO failed_parameter
END IF
IF(ISEQUAL(ftp_user,""))
     PRINT("Missing Parameter #3, user, exiting.")
     GOTO failed_parameter
END IF
IF(ISEQUAL(ftp_password,""))
     PRINT("Missing Parameter #4, password, exiting.")
     GOTO failed_parameter
END IF

LocalWebFolder = CONCAT("D:\Backups\Websites\",ftp_customername)
# Test if directory exists, if not create it
result_directory=LOCALCHDIR(LocalWebFolder)
IF(NOT(ISEQUAL(result_directory,"OK")))
     PRINT("Creating folder.")
     result_makedirectory = LOCALMKDIR(LocalWebFolder)
     IF(NOT(ISEQUAL(result_makedirectory,"OK")))
          PRINT("Directory Creation Failed, exiting.")
          EXEC(blat_cmd_line3)
          GOTO failed_directory
     END IF
END IF
LOCALCHDIR(LocalWebFolder)


:sync_reconnect
# Connect to FTP server
# Try to connect three times.
attempts="1"
:connect
PRINT("_____Connecting_____")
result_ftp=OPENHOST(ftp_server,ftp_user,ftp_password)
IF(NOT(ISEQUAL(result_ftp,"OK")))
     PRINT(CONCAT("Cannot connect! Attempt #",attempts,"."))
     IF(ISEQUAL(attempts,"3"))
     EXEC(blat_cmd_line1)
     GOTO failed_connection
ELSE
     attempts=ADD(attempts,"1")
     SLEEP("3")
     GOTO connect
     END IF
END IF

# if ftp_ignoredirectory exists
# then do not attempt download of this
IF(NOT(ISEQUAL(ftp_ignoredirectory,"")))
     ADDEXCLUSION(DOWNLOAD,ftp_ignoredirectory)
     PRINT(CONCAT("IGNORING Directory ",ftp_ignoredirectory))
END IF

# syncronize from remote files
result_sync=SYNC(LocalWebFolder,ftp_remotepath,DOWNLOAD,SUBDIRS)
#426 is Connection closed; transfer aborted.
IF(ISEQUAL(result_sync,"426"))
     PRINT("Error sending/receiving files.")
     PRINT(CONCAT("result_sync reports is >",result_sync,"<."))
     GOTO retry_sync
END IF
#425 is Can't open data connection, usually because of a timeout
IF (ISEQUAL(result_sync,"425"))
     PRINT("Error sending/receiving files.")
     PRINT(CONCAT("result_sync reports is >",result_sync,"<."))
     GOTO retry_sync
END IF
#3 is Not connected and not logged in to remote server
IF (ISEQUAL(result_sync,"3"))
     PRINT("Error sending/receiving files-- Retrying!")
     PRINT(CONCAT("result_sync reports is >",result_sync,"<."))
     GOTO retry_sync
END IF
#4 is Connection Timeout
IF (ISEQUAL(result_sync,"4"))
     PRINT("Error sending/receiving files-- Retrying!")
     PRINT(CONCAT("result_sync reports is >",result_sync,"<."))
     GOTO retry_sync
END IF

IF(NOT(ISEQUAL(result_sync,"OK")))
     PRINT("Error sending/receiving files-- Retrying!")
     PRINT(CONCAT("result_sync reports is >",result_sync,"<."))
     EXEC(blat_cmd_line2)
     GOTO failed_put
END IF

PRINT("Files downloaded succesfully.")
EXEC(blat_cmd_line4)
CLOSEHOST()
#SLEEP("60")
EXIT(99)

:retry_sync
PRINT("Retrying Synchronization...")
email_subject3=CONCAT("**ERROR #",result_sync,", retrying ScriptFTP for ",ftp_customername)
EXEC(blat_cmd_line6)
SLEEP("30")
CLOSEHOST()
GOTO sync_reconnect


:failed_put
PRINT("An Error was found while synchronizing the files.")
CLOSEHOST()
#SLEEP("60")
EXIT(1)

:failed_connection
PRINT("Cannot connect to remote host.")
#SLEEP("60")
EXIT(2)

:failed_directory
PRINT("An Error was found while creating the folder.")
CLOSEHOST()
#SLEEP("60")
EXIT(3)

:failed_parameter
PRINT("An Error was found, missing a parameter.")
EXEC(blat_cmd_line5)
CLOSEHOST()
SLEEP("30")
EXIT(4)




Copyright 2004-2007 ScriptFTP software
[Contact]  [About]  [PAD file]
ScriptFTP software is a developer member
of the Association of Shareware professionals