the REXX Files- by Dirk Terrell

I've seen several people in the newsgroups lately asking about ways to do automated downloading or uploading by FTP. It is certainly possible to do simple tasks by feeding a response file into the standard input of the command line FTP program (FTPPM) that comes with Warp, but you can quickly run into limitations with that method. REXX, not surprisingly, offers a more flexible solution using the RXFTP library from IBM

RXFTP is an extension to REXX that enables it to perform FTP functions. If you have Warp Connect's TCP/IP installed, you will find RXFTP.DLL in the \tcpip\dll directory. If you don't have Warp Connect, you can find the necessary files at the Watson ftp site (ZIP, 84K).

As with any REXX library you have to load the library in your program. This is done with the following two lines of code:

rc = RxFuncAdd("FtpLoadFuncs","RxFtp","FtpLoadFuncs")
rc = FtpLoadFuncs()

(I typically use the variablerc to hold thereturncode from function calls.)

Once you have the library loaded, you can then use the library functions to perform various tasks. If you have some familiarity with command line FTP, then the function names will be quite familiar. The first step is to log into an FTP server, and this is done with theFTPSetUser function. The syntax is:

as in:
rc = FTPSetUser("","anonymous","")
Next, you may want to change to a particular directory on the remote site. TheFtpChDir function is used to change directories with the following syntax:
Once you're in the right place, you will probably want to look at what's available in the directory. You can use eitherFtpLs orFtpDir to get a directory listing. FtpLs returns the compact directory listing with just the file and directory names.FtpDir returns the detailed listing with dates, file sizes,etc. The calling syntax is the same in either case:
wherepattern is a search pattern for files (as in *.txt or *.zip) andstem is a REXX stem variable (similar in some ways to arrays in other languages) to hold the results. A stem variable is one that ends with a "." such as "FileList.", so a call to these functions would look like:
Upon return, the stem variable will hold the files that match the search pattern. The ".0" stem value will hold the number of items in the rest of the stem. So, to do something with the file list that has been placed in the stem variableFile., you would loop from 1 to File.0 like this:
Do i=1 to File.0
Say "File number" i "is" File.i
/* Do other processing on each file here */
Of course the whole purpose of FTP is to transfer files either to the remote machine ("put" a file) or from the remote machine ("get" a file). These functions are done withFtpPut andFtpGet. The syntax for these functions is
FtpGet(LocalFile,RemoteFile[,"Binary" | "Ascii"])
FtpPut(LocalFile,RemoteFile[,"Binary" | "Ascii"])
whereLocalFile is the name of a file on the local machine andRemoteFile is the name of a file on the remote machine. The third parameter in the function call tells whether the transfer should be done in binary mode or ascii mode (text files only).

There are some other functions in the RXFTP library (such as creating/deleting directories), but this is enough to get you started. As an example of what you can do with this library, I wrote a little program that logs in Hobbes and gets the files with .txt or .TXT extensions in the /incoming directory and puts them into one file for perusal with a text editor. This is something that went together quickly, so a lot of error checking is skipped and you will probably want to modify it to work better. (One enhancement would be to eliminate the case sensitivity of the file searching.) But, it should serve the purpose of getting you started with the RXFTP library.

Dr. Dirk Terrell is an astronomer at the University of Florida specializing in interacting binary stars. His hobbies include cave diving, martial arts, painting and writing OS/2 software such as HTML Wizard.

[Index]  [ Previous] - [Feedback] - [Next ]

[Our Sponsor: Prominic Technologies - Software developer and IBM PC VAR preloading OS/2.]

This page is maintained by Falcon Networking. We welcome your suggestions.

Copyright © 1996 - Falcon Networking