29
Fri, Nov
0 New Articles

Exploiting the OS/2 REXX FTP Function Set

General
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

TP: The Power to Join Heterogeneous Systems

In the past, enterprises have used a variety of methods to move data between different operating systems. For example, the AS/400’s Send Network file (SNDNETF) command can transfer files between SNA-networked AS/400s or to SNA-connected mainframes. From a workstation, among other techniques, you can transfer files to MVS- and VM-based systems using IND$FILE. Unfortunately, most users have never had a single method that could be used to transfer files between all heterogeneous systems. There was a method available, but it wasn’t widely used. Today—with the increased acceptance of TCP/IP—this tool runs on practically every operating system. This “new” file transfer standard goes by the very short name of FTP.

Most users are familiar with FTP. In fact, you might already be using its archaic command-line interface to GET or PUT a file, perhaps even to list (ls) a file’s members or to print a working directory (pwd). Maybe you’ve appreciated FTP’s power, but found it lacking in the area of usability. OS/2’s Presentation Manager-enhanced FTP interface, FTPPM, certainly makes accessing files easier with its GUI. But why stop there? Why not tap into the power and flexibility of FTP via its REXX API? This article shows you how to do just that.

The OS/2 REXX FTP API

REXX is not exactly the language of choice among IT propeller heads, but it’s easy to use, flexible, and is supported by many add-on function sets. It’s also IBM’s Systems Application Architecture (SAA) procedure language, which means that the REXX skills you develop on the AS/400 can be used on OS/2- and OS/390-based systems, as well as on the many non-IBM platforms that support REXX, including Windows NT. The


OS/2REXX FTP function set lets a REXX program invoke many of the common FTP functions programmatically.

Usage Scenarios

Imagine the possibilities available with a programmable interface to FTP from your workstation. Your REXX application might, for example, transfer a unique set of files at a specified interval between the client workstation and a server (an AS/400, another workstation, a mainframe, or any system running the FTP daemon). This transfer could be used as part of a backup plan or a synchronization process, i.e., a REXX program can get a unique set of files every twelve hours as a backup, or it can compare the files’ contents and keep only the newer ones to synchronize files on the host and workstation on a more frequent basis.

A particularly powerful OS/2 REXX FTP function is FtpProxy, which lets a workstation user orchestrate file transfers between two host machines.

The sample REXX program in Figure 1 and its interface shown in Figure 2 illustrate how simple it is to connect to a server and display or download files. The program makes use of a simple character-based display, but don’t stop there! Go crazy; exploit VREXX and design your own customized file transfer interface.

REXX FTP Function Set

If you’re already familiar with FTP, most of the REXX FTP API functions are intuitive. For example, where you would manually type get, your REXX program will call FtpGet; where you would type ls to list file/member names on the server, your REXX program will call FtpLs. Even if you’ve never FTPed a file in your life, you’ll find the OS/2 REXX FTP function set quite understandable:

• FtpLoadFuncs and FtpDropFuncs—These functions load and unload the registered REXX FTP function set as part of normal REXX housekeeping. Refer to the sample REXX program for syntax.

• FtpVersion—FtpVersion(varname) sets varname to a string representing the version of the REXX FTP API package installed.

• FtpSetUser and FtpLogoff—FtpSet- User(server,user,pswd,account) specifies the server, user, password, and optional account information used by subsequent REXX FTP functions. Note that FtpSetUser doesn’t actually log on to the remote server; the logon occurs with the execution of the next FTP function requiring service, e.g., FtpPwd or FtpDir. FtpLogoff() ends the FTP session with the server named on a prior FtpSetUser call and resets the server, user, password, and account information specified with that call. Refer to the sample REXX program for syntax.

• FtpLs and FtpDir—FtpLs(pattern, stemname) and FtpDir(pattern,stemname) display directory information for the current remote directory, FtpLs in short format and FtpDir in long format. The resulting file/member list is placed in the REXX stemmed variable passed to the function. The populated stem variable’s elements can then be interpreted as follows: stemname.0 is the number of data elements returned; stemname.1 to stemname.n are those elements. The pattern passed to FtpLs and FtpDir can be a qualified file or a mask where an asterisk (*) and question mark (?) determine which file descriptions are returned. The asterisk substitutes for any character or group of characters; the question mark substitutes for only a single character. Refer to Figure 1 for sample usage.

• FtpPwd—FtpPwd(varname) or Print Working Directory sets varname to a string representing the current working directory.

• FtpChDir—FtpChDir(chdir) changes the working directory on the remote host to the directory specified in the variable chdir. Standard FTP directory navigation rules apply.


• FtpMkDir—FtpMkDir(newdir) creates a new directory on the remote host with the name specified in the variable newdir.

• FtpRmDir—FtpRmDir(olddir) removes the existing directory from the remote host specified in the variable olddir.

• FtpSetBinary—FtpSetBinary(“Binary “|”Ascii”) sets the default text translation for functions that transfer files, i.e., FtpGet, FtpPut, FtpAppend, and FtpPutUnique.

• FtpAppend—FtpAppend(Lfile,Rfile) appends a local file (Lfile) to the named remote file on the server (Rfile).

• FtpDelete—FtpDelete(Rfile) deletes the file Rfile on the remote host.
• FtpRename—FtpRename(oldname, newname) renames a file on the server.
• FtpGet—FtpGet(Lfile,Rfile) copies a file from the server (Rfile) to the local workstation (Lfile).

• FtpPut—FtpPut(Lfile,Rfile) copies a file from the local workstation (Lfile) to the server (Rfile).

• FtpPutUnique—FtpPutUnique (Lfile,Rfile) copies a file from the workstation (Lfile) to the server (Rfile), ensuring the server file name is unique so that it will not overwrite an existing file.

• FtpQuote—FtpQuote(string) sends the string to a server if the server supports FTP commands via QUOTE. You can use FtpQuote to execute remote commands on the AS/400.

For an example of how this works, see the article titled “Exploiting Remote Command Execution Across IBM Operating System Platforms” in the September/October 1997 issue of Client Access/400 Expert. The references at the end of this article can also provide you with additional information.

• FtpSite—FtpSite(info) sends site-dependent information to the server if it supports the site command.

• FtpSys—The FtpSys(varname) sets varname to a description of the operating system running on the server.

• FtpProxy—This is a powerful function that can copy files from one server to another. Sample invocation: FtpProxy(host1, userid1, password1, account1, host2, userid2, password2, account2, file1, file2).

• FtpPing—FtpPing(server,packet_ length) pings the named server with a packet of the specified length. Refer to the “REXX FTP Function Return Codes” sidebar on page 25 for the unique FtpPing return codes.

Conclusion

FTP is a popular tool that can be used to transfer files across heterogeneous operating systems. It is generally accessed via a clumsy command-line interface or limited- function GUI, but the OS/2 REXX API unleashes the power of FTP, empowering a workstation user to programmatically list and transfer files between a workstation and a host or between two remote hosts.

References

The following references are broken down by subject matter: FTP, REXX, and VREXX.

FTP References

AS/400 TCP/IP Configuration and Reference (SC41-3420-x) “Exploiting Remote Command Execution Across IBM Operating System


Platforms,” Client Access/400 Expert, September/October 1997 IBM TCP/IP for MVS, User’s Guide (SC31-7136-x) IBM TCP/IP for OS/2: User’s Guide (SC31-6075-x) REXX FTP API (an .INF file available in the TCPIPDOC directory)

REXX References

OS/2 Procedures Language/2 REXX (an .INF file in the OS/2 Information folder) The REXX Language: A Practical Approach to Programming,

Michael Cowlishaw, Prentice Hall, Englewood Cliffs, New Jersey: 1990 The REXX Language page at IBM Hursley: http://rexx.hursley.ibm.com/rexx/

rexxibm.htm Newsgroup: comp.lang.rexx VREXX References “A Visual OS/2 REXX Primer,” Client Access/400 Expert,

January/February 1997 “A Visual OS/2 REXX Primer: Advanced Functions,” Client Access/400 Expert,

March/April 1997

/* rexx */
/* */

/* Copyright 1998 Chris Miksanek. */
/* All Rights Reserved. */
/* */

/* This file is supplied "AS IS". The author */
/* does not provide any warranties, express */
/* or implied, including, but not limited to, */
/* the implied warranty fitness for any */
/* particular purpose. */

exitrc = 4 /* Default bad rc */
mboxsize = 79 /* display box width */
displines = 18 /* screen real estate */

/* Register and load REXX FTP Functions */
Rc = RxFuncAdd(" FtpLoadFuncs","rxFtp","FtpLoadFuncs")
Rc = FtpLoadFuncs( NoCR)

/* Retrieve command line args */
parse arg FTPserver FTPuser FTPpswd

cls

/* Prompt for unsupplied parms */
if FTPserver = '' then do

say 'Enter server name'

parse pull FTPserver

end
if FTPuser = '' then do

say 'Enter user for' FTPserver

parse pull FTPuser

end
if FTPpswd = '' then do

say 'Enter password for' FTPserver||'.'||FTPuser

parse pull FTPpswd
cls /* clear after pswd typed */

end

/* Display REXX FTP function set version */
say ' '
ftpVersion( FTPv)
call Message_Box 'REXX FTP Version:'||FTPv

/* PING server, exit if server not available */


call Message_Box,

'PINGing '||FTPserver||' ... wait ...'
rc = FtpPing(FTPserver,16)
if datatype(rc) <> NUM then do call Message_Box,

'PING to ('||FTPserver||') failed... rc: '||rc

signal quit

end
call Message_Box 'PINGed in '||rc||' ms'

/* Set server and user information */
rc = FtpSetUser(FTPserver, FTPuser, FTPpswd)

/* Get initial working directory */
rc = FtpPwd(dirName)
If rc <> 0 then do call Message_Box 'FTPdir Failed, rc:' FTPERRNO

signal quit

end

Rc = FtpSys(ServerInfo) /* Get Server info*/

/* Loop here until user enters "END" */
do forever

cls

call Message_Box ServerInfo

call Message_Box dirName /* Display WD */

call Message_Box, /* Prompt */

'Enter new directory, [CR], or END'

parse pull NewDir /* Get new dir */

if translate(newDir) = 'END' then do

exitrc = 0 /* OK end rc */

signal quit /* quit */

end

if NewDir <> '' then do /* process new wd */

Rc = FtpChDir(NewDir) /* change wd */

If Rc <> 0 then do /* wd change OK? */

call Message_Box, /* nope, ignore */

'FTPchDir failed, rc: '||FTPERRNO||,

'. Press [ENTER] to continue'

pull x

iterate /* loop back */

end

else do

DROP dirName /* APAR#: PN80464 */

rc = FtpPwd(dirName) /* Get new WD */

If rc <> 0 then do /* OK? */

Say 'FTPPwd Failed, rc:' FTPERRNO

signal quit /* No, exit */

end

cls

call Message_Box dirName

end

end

/* Extract WD name from WD message */

parse var dirName . '"' realDir '"' .

cls

call Message_Box,

'Listing files in '||realDir||' ... wait ...'

Rc = FtpLs('*','FTPfiles.')

If Rc <> 0 then Say 'List Failed, rc:' FTPERRNO

else do

cls

if FTPfiles.0 < displines then max = FTPfiles.0

else max = displines /* screen size */

call Message_Box realDir||' files 1 to '||max

do i = 1 to FTPfiles.0 /* list directory */

say right(i,3)||'.' FTPfiles.i

/* If screen filled, pause and clear */

if i // displines = 0 then do

call Message_Box,

'Paused... press [ENTER] to continue'

pull x

cls

if FTPfiles.0 < i+displines then max = FTPfiles.0

else max = i+displines

call Message_Box,


realDir||' files '||i+1|| ' to '||max

end

end i

/* Prompt for d/l option */

call Message_Box,

'Specify file # to download to workstation',

'or press [ENTER] to continue'

pull x

if x <> '' then do /* d/l? */

cls

if ((x < 1) | (x > FTPfiles.0)) then do

call Message_Box, /* invalid file # */

'Invalid file number.',

'Press [ENTER] to continue'

pull x

end

else do

len = length(FTPfiles.x) /* Trim? */

if len > 8 then len = 8 /* yes */

locname = substr(FTPfiles.x,1,len)

call Message_Box,

'Getting file '||FTPfiles.x||,

' as '||locname||'.FTP'

rc = FtpGet(locname||'.FTP',FTPfiles.x,"Ascii")

cls

call Message_Box,

'FTP Get rc: '||FTPERRNO||,

'. Press [ENTER] to continue'

pull x

end /* d/l file */

end

end

end /* do forever */

Quit:

Rc = FtpLogoff() /* House */

Rc = FtpDropFuncs() /* keeping */

call Message_Box 'Goodbye :-)'

exit exitrc

Message_Box:

parse arg mdata

mdata = left(mdata,mboxsize-4)

say '/'||left('',mboxsize-2,'ƒ')||'ø'

say '[.greaterequal] ' ||mdata||' [.greaterequal]'

say '¿'||left('',mboxsize-2,'ƒ')||'Ÿ'

return

/* */

Figure 1: Sample REXX program to view server directories and optionally download displayed files.


Exploiting_the_OS-2_REXX_FTP_Function_Set07-00.jpg 400x265

Figure 2: Results of sample REXX program displaying an OS/400 physical file. With so many files available for download, how do you choose?

REXX FTP Function Return Codes

The REXX FTP API return codes are slightly different than those of other functions. They’re a bit more difficult to handle, but a great deal more informative. FtpSetUser and FtpSetBinary are probably the least complicated, but then again the functions don’t do much, either. Each validates only the string passed. The functions return a value of 1 if the string passed is valid and a value of 0 if it is invalid. Remember that FtpSetUser doesn’t actually log on to the server, so a good return code at that point doesn’t really mean much. FtpPing is a unique function. It can return a numeric or a descriptive character string (refer to the sample REXX program for FtpPing return code interpretation). If the return code is numeric, it means the ping was successful and the numeric value is the number of milliseconds the ping took to return. If the value is nonnumeric, it will be one of the following:
• PINGREPLY—The server did not reply.
• PINGSOCKET—Ping was unable to obtain a socket.
• PINGPROTO—Unknown protocol.
• PINGSEND—The ping send failed.
• PINGRECV—The ping receive failed.
• PINGHOST—Attempting to ping an unknown host All of the other REXX FTP API functions return either a 0 for a successful call or a -1 for a failure. If the function returns a -1, the REXX variable FTPERRNO will contain one of the following:
• FTPSERVICE—The function was requesting an unknown service.
• FTPHOST—The function was attempting to connect to an unknown host.
• FTPSOCKET—The function was unable to obtain a socket.
• FTPCONNECT—The function was unable to connect to the server.
• FTPLOGIN—The function’s login failed.
• FTPABORT—The file transfer stopped.
• FTPLOCALFILE—There was a problem opening the local file.
• FTPDATACONN—There was a problem initializing the data connection.
• FTPCOMMAND—The command failed.
• FTPPROXYTHIRD—A proxy server does not support third-party transfers.
• FTPNOPRIMARY—There was no primary connection for the proxy transfer.


BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: