Installing Robo-FTP as a Windows Service
|Top Previous Next|
Why should I run a Robo-FTP script as a Windows Service?
A Windows service is a background process which is loaded by the Service Control Manager of the Windows kernel. Because Windows services can be configured to load at boot up, before any user logs in, and are often independent of any specific user being logged on at the time, it can be easier to maintain consistent uptime with your script when it runs as a Windows service. Alternately, if you choose to configure your service to not be launched automatically by the system at boot time, it can instead be manually launched by a user at the console via the Windows Service Manager tool or the Enterprise Dashboard.
What do I need to consider when writing a script that will run as a Windows service?
When writing a script to be run as a service, there are some special considerations that apply. While many of these considerations are also relevant when writing a non-service script, they are especially significant when it comes to service scripts because they must be designed to run unattended:
Since service scripts are designed to run continuously in the background, they are generally not supposed to terminate. Because a script will terminate once it reaches its end, a looping command should be used to allow your script to continue processing. One common way of doing this is with the GOTO and PAUSE commands, as shown in the following example:
:loop ;; "loop" label
FTPLOGOFF ;; main script contents: download files from "mysite"
PAUSE /for=300 ;; wait 5 minutes before the next round of downloads
GOTO loop ;; jump back to the "loop" label above
File and folder permissions must be considered when deciding which Windows account will be used to run the service. For example, the account used must have permission to log in as a service. Permissions are usually to blame if a script works fine when you run it in the main console windows but fails when launched as a service.
The default service account is the built-in LOCAL SYSTEM account but it does not have access to network resources. Use a local or domain account with sufficient permissions (for example, the NETWORK SERVICE account) if your script reads or writes files on the LAN.
Since your service script will be designed to run unattended and continuously, it is worthwhile to be extra diligent when it comes to checking for possible errors returned by script commands. Common errors to check for include failed logons due to intermittent network issues and local filesystem navigation issues due to insufficient permissions. Handling errors up front is a great way to increase the resilience of your script and also to reduce script development time by reducing time spent hunting down problems. Liberal use of the IFERROR command is recommended.
For more information about these and other considerations, see Programming Service Scripts.
How do I install my script as a service?
Robo-FTP provides three ways to install a script as a Windows service:
(1) With Robo-FTP's Service Installer program, as a GUI
(2) With Robo-FTP's Enterprise Dashboard program
(3) With the same Service Installer program, but from the command line
The first method is by far the most common way to install your new service. In the vast majority of cases, it involves just 4 small steps:
(1) Give your service a unique name
(2) Select your script
(3) Specify the user under which the service and script will run
(4) Click the "Install" button
The Service Installer
You can also use the Robo-FTP Enterprise Dashboard program to install your service using a similar process. See the "How do I monitor my script?" section below for more information
about the Dashboard.
How do I monitor my script?
With the Robo-FTP Enterprise Dashboard, the status of all your services are displayed in real time. Your scripts can make use of the DASHBOARDMSG command to also give status updates
about their current activity, which will instantly appear on the Dashboard window. This makes it easy to keep tabs on what each service is doing. You can even right-click on each running
service, select "View", and watch each command as it executes, line-by-line.
The Robo-FTP Dashboard
See also: Robo-FTP Dashboard
The Monitor program is another option for keeping an eye on a Robo-FTP Service script. The Monitor is a Windows system tray applet that you can use to monitor the status of any Robo-FTP service, right from your Windows taskbar. You can quickly see if your service is running or not, see what operation the script is currently performing, and watch each individual command execute line-by-line.
The Robo-FTP Monitor
See also: Robo-FTP Monitor