14
Thu, Nov
2 New Articles

FTP Made Easier

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

Drawn from the need to send objects between different machines, IBM's SNADS was a relatively rich architecture used to send objects between AS/400s. Today, with FTP over TCP/IP being the dominant choice for file transfer, many people want FTP to be as easy as (or easier than) SNADS.

Why FTP? Because configuring my machine so that I can send you a source member is nothing short of rocket science. With FTP, I simply provide the IP address and the file I want to send and--bam!--it gets sent.

The downside of FTP is that you have to write an FTP script or start the interactive FTP session. This isn't difficult at all, unless you haven't used FTP before. Using a script is nice, but it does require that you know what you're doing; the interactive session is OK, but it can get to be tedious for simple transfers or transfers that need to be run frequently.

What I want is a command that allows me to say something like "Send this file using FTP. Here are the IP address, user ID, and password. Now, go do it." But no such CL command exists.

My choices are to write a new script each time a user needs to send a different file, to write a ridged script that works only in one particular situation, or to invent a CL command that handles most of the situations. I choose to write a CL command.

Send a File Using FTP

The Send File Using FTP (FTPSNDFILE) command has a long list of parameters that allows you to send any file directly through FTP without starting the interactive FTP session or writing an FTP script. The FTPSNDFILE command builds an FTP script on the fly and then runs it by calling the FTP command.

You can specify a remote system IP address or domain, the file and member you want to send, and the target location. As is usually the case with CL commands that I write, I've selected a good set of default parameter values so that you have to know only the IP address, file name, user profile, and password. The rest of the parameters can be left to default. Here's a description of the parameters.

RMTSYS--Remote system. Specify the IP address or domain name of the system that will receive the file you are sending.

FILE--Local file name. Specify the qualified name of the file that you want to send using FTP. A value of *LIBL may be specified for the file's library. However, the FTPSNDFILE command's processing program will convert *LIBL into the actual library name at runtime.

MBR--Local member name. Specify the name of the member that you want to send. The default member name is *FIRST, but you may specify*FILE, *LAST, or *ALL. In addition, you may specify a generic member name.

TOFILE--Remote file name. Specify the name of the file that will receive the data from the file you are sending. The file should already exist so that the external description is preserved. If the file does not exist, the FTP server will create the file for you, but you won't like the results (a flat file).

TOMBR--Remote member name. Specify the name of the member into which the data is stored. You may specify either a member name or one of the following special values:

  • *FROMMBR--Use this when the remote member name should be the same as the local member name specified on the MBR parameter. This value must be specified when a generic local member name is specified or when *ALL is specified for the local member name (MBR) parameter.
  • *TOFILE--The member name is the same as the remote file name specified on the TOFILE parameter.

REPLACE--Replace remote member's data. This parameter adds the "(Replace parameter" to the FTP PUT command. Yes, FTP uses "(Replace" to indicate REPLACE(*YES). However, this parameter has no impact on the results when iSeries-to-iSeries transfers are being performed. On the iSeries, the target file/member's data is always replaced. Therefore, this parameter is reserved for future use.

USER--Remote FTP user profile. Specify the user profile of the user that is needed to sign onto the remote system.

PWD--Remote FTP user's password. Specify the password for the remote user. Note that this parameter's value is not recorded in the joblog and must be entered each time you run FTPSNDFILE from the command entry display. From within a CL program, the password can be stored in a CL variable.

MODE--Transfer mode. Specify the kind of transfer to be performed. The valid choices are as follows:

  • *BINARY--The transfer mode is IMAGE/BINARY. This is recommended for iSeries objects such as database files.
  • *ASCII--The transfer mode is plain ASCII text. This transfer mode is valid for non-database files, such as source file members.

SRCFILE--The name of the source that will receive the generated FTP script. This source file should be as long as possible but at least 152 bytes in length (140 bytes for the source line and the usual 12 bytes for the source sequence and change dates area).

If this source file does not exist, it will be created with a record length of 152 bytes. The default source file name is as follows: Source file QFTPSRC, Library QTEMP.

SRCMBR--The FTP script source member name. This is the name of the member into which the FTP script is generated. Specify any valid source member name, *FROMMBR, or *GEN. If the member exists, it is cleared; if it does not exist, it is added. The two special values for this parameter are as follows:

  • *FROMMBR--The name specified on the MBR parameter is used as the member name for the FTP script. This member is added to the source file specified on the SRCFILE parameter.
  • *GEN--A member name using the following pattern is automatically generated: FSyyyymmdd, where FS is a constant, and YYYYMMDD is today's system name in YMD format.

LOG--FTP message logging file. Specify the name of a source file that will receive the messages generated by the FTP command. Optionally, specify that the messages are to be delivered as they normally are, via the STDOUT (standard output) device. This parameter has the following special values:

  • *STDOUT (or *STDIO)--Indicates that the FTP log is written to the standard output device, which scrolls up the 5250 screen, similar to an old teletype interface.
  • *NONE--The FTP log is not displayed.

Unlike the SRCFILE parameter, the file specified on the LOG parameter must exist because the FTPSNDFILE command will not create it. You may, however, use the same file name as the SRCFILE parameter, in which case the file is created due to its being specified on the SRCFILE parameter.

LOGMBR--The member name where the FTP log is saved.

DSPLOG--Display the FTP log. If *YES is specified, the FTP log is displayed when the FTP transfer completes; if *NO, the FTP log is not displayed.

As always, you can download the source from my RPGLab Web site. The command definition source code for the FTPSNDFILE command is reproduced below, but the RPG IV source of the command processing program is a bit too lengthy to reproduce here. So visit the Web site to download the RPG IV source.

FTPSNDFILE:  CMD        PROMPT('Send File Using FTP')

             /**********************************************/
             /*  Command processing program is FTPSNDFILE  */
             /*--------------------------------------------*/
             /*  REQUIREMENTS:  FTP server must be active. */
             /*                 The LOG file must exist    */
             /*                 and should be a source     */
             /*                 79 or 80 bytes in length.  */
             /*                 A traditional source file  */
             /*                 is valid as a log file.    */
             /**********************************************/

 IP:         PARM       KWD(RMTSYS) TYPE(*CHAR) LEN(128) MIN(1) +
                          EXPR(*YES) PROMPT('Remote IP or FTP server')

 FROMFILE:   PARM       KWD(FILE) TYPE(QUAL1) MIN(1) PROMPT('Local +
                          file')
             PARM       KWD(MBR) TYPE(*GENERIC) LEN(10) DFT(*FIRST) +
                          SPCVAL((*FILE) (*FIRST) (*LAST) (*ALL)) +
                          EXPR(*YES) PROMPT('Local member')
 QUAL1:      QUAL       TYPE(*NAME) LEN(10) MIN(1) EXPR(*YES)
             QUAL       TYPE(*NAME) DFT(*LIBL) SPCVAL((*LIBL)) +
                          EXPR(*YES) PROMPT('Library')

 TOFILE:     PARM       KWD(TOFILE) TYPE(QUAL2) PROMPT('Remote file')
 TOMBR:      PARM       KWD(TOMBR) TYPE(*NAME) LEN(10) DFT(*FROMMBR) +
                          SPCVAL((*FROMMBR) (*TOFILE)) EXPR(*YES) +
                          PROMPT('Remote member')
 QUAL2:      QUAL       TYPE(*NAME) LEN(10) DFT(*FROMFILE) +
                          SPCVAL((*FROMFILE)) EXPR(*YES)
             QUAL       TYPE(*NAME) DFT(*FROMLIB) SPCVAL((*FROMLIB)) +
                          EXPR(*YES) PROMPT('Library')


 REPLACE:    PARM       KWD(REPLACE) TYPE(*LGL) LEN(1) RSTD(*YES) +
                          DFT(*YES) SPCVAL((*YES '1') (*NO '0')) +
                          EXPR(*YES) PROMPT('Replace data on remote +
                          system')

 USER:       PARM       KWD(USER) TYPE(*CHAR) LEN(64) DFT(*CURRENT) +
                          SPCVAL((*CURRENT)) EXPR(*YES) +
                          PROMPT('Remote FTP User ID')
 PWD:        PARM       KWD(PWD) TYPE(*CHAR) LEN(64) DFT(*USERID) +
                          EXPR(*YES) DSPINPUT(*PROMPT) +
                          PROMPT('Remote FTP Password')

 MODE:       PARM       KWD(MODE) TYPE(*CHAR) LEN(10) RSTD(*YES) +
                          DFT(*BINARY) SPCVAL((*BINARY BINARY) +
                          (*TEXT ASCII) (BINARY) (ASCII) (TEXT +
                          ASCII)) EXPR(*YES) PROMPT('Transfer mode')

 SRCFILE:    PARM       KWD(SRCFILE) TYPE(QUAL3) PROMPT('Source file +
                          for FTP script')
             PARM       KWD(SRCMBR) TYPE(*NAME) LEN(10) +
                          DFT(*FROMMBR) SPCVAL((*FROMMBR) (*GEN)) +
                          EXPR(*YES) PROMPT('Script source member')
 QUAL3:      QUAL       TYPE(*NAME) LEN(10) DFT(QFTPSRC) EXPR(*YES)
             QUAL       TYPE(*NAME) DFT(QTEMP) SPCVAL((*LIBL)) +
                          EXPR(*YES) PROMPT('Library')

  /*************************************************************/
  /**  The LOG member can be a source or database file.        */
  /**  A record length of 79 or 80 or more than 80 is needed.  */
  /**  If the log file does not exist, it is created for you.  */
  /*************************************************************/
 LOG:        PARM       KWD(LOG) TYPE(QUAL4) DFT(*STDOUT) +
                          SNGVAL((*STDOUT) (*STDIO *STDOUT) +
                          (*NONE)) PROMPT('FTP log file')
             PARM       KWD(LOGMBR) TYPE(*NAME) LEN(10) +
                          DFT(*FROMMBR) SPCVAL((*FROMMBR)) +
                          EXPR(*YES) PROMPT('Log member')
 QUAL4:      QUAL       TYPE(*NAME) LEN(10) SPCVAL((QFTPLOG)) +
                          EXPR(*YES)
             QUAL       TYPE(*NAME) DFT(QTEMP) SPCVAL((*LIBL)) +
                          EXPR(*YES) PROMPT('Library')

  /*  The follow paramaeter is ignored when LOG(*STDIO) is specified.  */
 DSPFTPLOG:  PARM       KWD(DSPLOG) TYPE(*LGL) RSTD(*YES) DFT(*YES) +
                          SPCVAL((*YES '1') (*NO '0')) EXPR(*YES) +
                          PROMPT('Display FTP transfer log')

This version of the FTPSNDFILE command works best with database or source files. I am working on updating it to handle *SAVF (Save files) just as easily and will post that update in the RPGLab as soon as it is ready.

Bob Cozzi is a programmer/consultant, writer/author, and software developer. His popular RPG xTools add-on subprocedure library for RPG IV is fast becoming a standard with RPG developers. His book The Modern RPG Language has been the most widely used RPG programming book for more than a decade. He, along with others, speaks at and produces the highly popular RPG World conference for RPG programmers.

BOB COZZI

Bob Cozzi is a programmer/consultant, writer/author, and software developer. His popular RPG xTools add-on subprocedure library for RPG IV is fast becoming a standard with RPG developers. His book The Modern RPG Language has been the most widely used RPG programming book for more than a decade. He, along with others, speaks at and produces the highly popular RPG World conference for RPG programmers.


MC Press books written by Robert Cozzi available now on the MC Press Bookstore.

RPG TnT RPG TnT
Get this jam-packed resource of quick, easy-to-implement RPG tips!
List Price $65.00

Now On Sale

The Modern RPG IV Language The Modern RPG IV Language
Cozzi on everything RPG! What more could you want?
List Price $99.95

Now On Sale

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: