Last updated: December 6, 2010
Installation and Configuration
Error Code Reference
The STAF FTP service uses the FTP client support provided in Java to provide lower level FTP protocol handling via the java.net.URL class. The advantage to using this library is that it comes with Java and is public and documented. The disadvantages are that it implements RFC1738 rather than the newer RFC959 specification, and FTP URLs require that the connection close after every operation which is not very efficient for transferring many small files, and it lacks several useful features.
Note that JavaWorld conducted a formal review of FTP client libraries that are available here.
Download the FtpV103.zip/tar file from Get STAF Services into a local directory (e.g. C:/STAF/services or /usr/local/staf/services) and extract it.
Add the following statement to your STAF.cfg file:
SERVICE <Service Name> LIBRARY JSTAF EXECUTE <Service Jar File Name>
where:
Examples:
SERVICE FTP LIBRARY JSTAF EXECUTE {STAF/Config/STAFRoot}/services/ftp/STAFFTP.jar
SERVICE FTP LIBRARY JSTAF EXECUTE C:/STAF/services/ftp/STAFFTP.jar
Or, you can dynamically add the FTP service using the SERVICE service's ADD SERVICE request.
<cwd1>/<cwd2>/.../<cwdN>/<name>where <cwd1> through <cwdN> and <name> are (possibly encoded) strings. The <cwdx> parts may be empty. Also, the <name> part should be empty for a DIR request. The url-path is interpreted as a series of FTP commands as follows:
Within a name or CWD component, the characters "/" and ";" are reserved and must be encoded. The components are decoded prior to their use in the FTP protocol. In particular, if the appropriate FTP sequence to access a particular file requires supplying a string containing a "/" as an argument to a CWD or RETR command, it is necessary to encode each "/".
For example on a GET request, the url-path %2Fetc/myfile.txt is interpreted by executing "CWD /etc" and then "RETR myfile.txt". This has a different meaning from url-path etc/filefile.txt which would "CWD etc" and then "RETR myfile.txt"; the initial "CWD" might be executed relative to the default directory for the user that you used to login to the FTP host server. On the other hand, url-path /etc/myfile.txt, would "CWD " with a null argument, then "CWD etc", and then "RETR myfile.txt".
STAF client1 FTP HELP
Output:
FTP Service Help GET HOST <Host> [PORT <Port>] URLPATH <FTP URL File Path> FILE <Name> [USER <Name> PASSWORD <Password>] PUT HOST <Host> [PORT <Port>] URLPATH <FTP URL File Path> FILE <Name> [USER <Name> PASSWORD <Password>] DIR HOST <Host> [PORT <Port>] URLPATH <FTP URL Directory Path> [USER <Name> PASSWORD <Password>] VERSION HELP
The GET command downloads a file in binary mode from the remote FTP host and stores it on the STAF FTP service machine.
GET HOST <Host> [PORT <Port>] URLPATH <FTP URL File Path> FILE <Name> [USER <Name> PASSWORD <Password>]
HOST specifies the host name or IP address of the FTP server where the file you want to download resides. This option will resolve variables.
PORT specifies the port number to which the TCP connection is made on the remote FTP host machine. If the port is not specified, the default port for the ftp protocol is used instead. This option will resolve variables.
URLPATH specifies the FTP URL path to a file on the remote FTP host server that you want to download. See FTP URL Path for more information on the syntax for a FTP URL Path. This option will resolve variables.
FILE specifies the fully-qualified name of the file on the STAF FTP service machine where you want to store the file downloaded from the remote FTP host. This option will resolve variables.
USER specifies the user name that will be used in conjunction with specified password to login to the FTP host. The default is anonymous (to attempt an anonymous login to the FTP server). This option will resolve variables.
PASSWORD specifies the password that will be used in conjunction with the specified user name to login to the FTP host. The default is the registered name of the STAF FTP service followed by "@" and the logical name (e.g. host name) of the machine submitting the request to the FTP service. This option will resolve variables.
A valid user and password is required to login to the FTP host.
This command requires trust level 4.
On a successful return, the result buffer will be empty.
STAF local FTP GET HOST server1.company.com URLPATH /tests/test.zip FILE C:/myTests/test.zip USER tester PASSWORD !!@secret@!!
STAF local FTP GET HOST 9.3.99.999 PORT 2121 URLPATH ./tests/test1.jar FILE C:/test1.jar USER guest PASSWORD guest
STAF client1.company.com FTP GET HOST server1.company.com URLPATH ./test.zip FILE /tests/test.zip USER tester PASSWORD !!@secret@!!
STAF client1.company.com FTP GET HOST server1.company.com URLPATH ./test.zip FILE /tests/test.zip
The PUT command uploads a file in binary mode from the STAF FTP service machine to a remote FTP host server.
PUT HOST <Host> [PORT <Port>] URLPATH <FTP URL File Path> FILE <Name> [USER <Name> PASSWORD <Password>]
HOST specifies the host name or IP address of the FTP server where you want a upload a file to. This option will resolve variables.
PORT specifies the port number to which the TCP connection is made on the remote FTP host machine. If the port is not specified, the default port for the ftp protocol is used instead. This option will resolve variables.
URLPATH specifies the FTP URL path to a file on the remote FTP host server that you want to upload. See FTP URL Path for more information on the syntax for a FTP URL Path. This option will resolve variables.
FILE specifies the fully-qualified name of the file on the STAF FTP service machine that you want to upload to the remote FTP host server. This option will resolve variables.
USER specifies the user name that will be used in conjunction with specified password to login to the FTP host. The default is anonymous (to attempt an anonymous login to the FTP server). This option will resolve variables.
PASSWORD specifies the password that will be used in conjunction with the specified user name to login to the FTP host. The default is the registered name of the STAF FTP service followed by "@" and the logical name (e.g. host name) of the machine submitting the request to the FTP service. This option will resolve variables.
A valid user and password is required to login to the FTP host.
This command requires trust level 4.
On a successful return, the result buffer will be empty.
STAF local FTP PUT FILE C:/myTests/results.zip HOST server1.company.com URLPATH /builds/myProduct/results.zip USER tester PASSWORD !!@secret@!!
STAF LOCAL FTP PUT FILE /tests/test1.jar HOST 9.3.99.999 PORT 2121 URLPATH ./myProduct/tests/test1.jar
STAF client1.company.com FTP PUT FILE C:/tests.zip HOST server1.company.com URLPATH ./myProduct/tests.zip USER tester PASSWORD !!@secret@!!
The DIR command is used to list the contents of a directory on a remote FTP host server.
DIR HOST <Host> [PORT <Port>] URLPATH <FTP URL Directory Path> [USER <User Name> PASSWORD <Password>]
HOST specifies the host name or IP address of a FTP server. This option will resolve variables.
PORT specifies the port number to which the TCP connection is made on the remote FTP host machine. If the port is not specified, the default port for the ftp protocol is used instead. This option will resolve variables.
URLPATH specifies the FTP URL path to a directory on the remote FTP host server that you want to list the contents of. See FTP URL Path for more information on the syntax for a FTP URL Path. This option will resolve variables.
USER specifies the user name that will be used in conjunction with specified password to login to the FTP host. The default is anonymous (to attempt an anonymous login to the FTP server). This option will resolve variables.
PASSWORD specifies the password that will be used in conjunction with the specified user name to login to the FTP host. The default is the registered name of the STAF FTP service followed by "@" and the logical name (e.g. host name) of the machine submitting the request to the FTP service. This option will resolve variables.
A valid user and password is required to login to the FTP host.
This command requires trust level 2.
Upon successful return, the result buffer will contain a string containing a list of the contents of the directory. The format of this string will vary depending on the operating system of your FTP host server. Because the format varies, the results are returned as is, without any attempt to parse the contents.
For the following examples, the FTP host server, server1.company.com, is a Linux machine.
STAF local FTP DIR HOST server1.company.com URLPATH . USER tester PASSWORD !!@secret@!!
Result: The result could look similar to the following:
drwxr-xr-x 2 0 0 4096 Jul 30 2005 automate drwxr-xr-x 77 0 0 4096 Sep 24 15:21 build -rw-r--r-- 1 0 0 135669760 Oct 12 2006 hang.tar -rw-r--r-- 1 0 0 16752 Oct 12 2006 hang.xml -rw-r--r-- 1 0 0 63614186 Oct 12 2006 hangTest.zip drwxr-xr-x 3 0 0 4096 Sep 25 20:11 tools -rw-r--r-- 1 0 0 153115 Apr 23 00:07 test.zip drwxr-xr-x 5 0 0 4096 Jan 22 2007 vmware
STAF local FTP DIR HOST server1.company.com URLPATH ./tools/ USER tester PASSWORD !!@secret@!!
Result: The result could look similar to the following:
-rw-rw-rw- 1 0 0 20182856 Jul 30 2005 VMware-workstation-4.0.0-4460.exe drwxr-xr-x 6 0 0 4096 Aug 18 2005 server1 drwxr-xr-x 2 0 0 4096 Aug 18 2005 server2 drwxr-xr-x 2 0 0 4096 Jan 22 2007 server3
STAF local FTP DIR HOST server1.company.com URLPATH /build/win32/ USER tester PASSWORD !!@secret@!!
Result: The result could look similar to the following:
-rw-rw-rw- 1 0 0 13612644 Sep 17 03:12 STAF330-setup-win32-NoJVM.exe -rw-rw-rw- 1 0 0 49108598 Sep 17 03:12 STAF330-setup-win32.exe -rw-rw-rw- 1 0 0 13639235 Oct 02 12:07 STAF331-setup-win32-NoJVM.exe -rw-rw-rw- 1 0 0 49135189 Oct 02 12:07 STAF331-setup-win32.exe
For the following examples, the FTP host server, os2server, is a OS/2 machine (to show how the format of the list directory results varies by operating system).
C:\>STAF local FTP DIR HOST os2server URLPATH . USER guest PASSWORD guest Response -------- 0 DIR 03-24-08 15:03 330beta1 C:\>STAF local FTP DIR HOST os2server URLPATH ./330beta1 USER guest PASSWORD guest Response -------- 0 DIR 03-24-08 15:05 aix 0 DIR 03-24-08 15:08 hpux 0 DIR 03-24-08 15:04 linux 0 DIR 03-24-08 15:10 macosx-i386 0 DIR 03-24-08 15:07 solaris 0 DIR 03-24-08 15:03 win32 C:\>STAF local FTP DIR HOST os2server URLPATH ./330beta1/aix USER guest PASSWORD guest Response -------- 27063831 A 10-01-08 12:06 aix.bin 27063831 A 03-24-08 15:06 STAF330Beta1-setup-aix-NoJVM.bin 86046231 A 03-24-08 15:06 STAF330Beta1-setup-aix.bin
STAF client1 FTP VERSION
Output:
1.0.3
In addition to the common STAF return codes, the following service
return codes are defined for the FTP service:
Error Code | Meaning | Comment |
4001 | FTP host connection error | Could not open a connection to the specified FTP host. Additional information about the error is provided in the result. |