Tip

Dynamically transfer files via FTP

Tim Granatir, Search400.com expert

Here is a general-purpose program that dynamically creates an AS/400 FTP script, runs the FTP and then checks for errors. This program can be called from a job stream to dynamically transfer a file. Although this program is fully functional as is, I prefer to think of it more as a starting point for more specific types of processes.

If you are using to this to transfer save files from one AS/400 system to another, you'll want to make sure that the binary is added to your FTP script file. Also, when transferring save files, I prefer to add NAMEFMT 1 to my FTP script file so that I don't have to pre-create the save file on the system that will be receiving the save file. If you use NAMEFMT 1, you will have to specify file names in a directory type format such as /qsys.lib/mylib.lib/mysavf.savf


Tim Granatir

In the manuals, it says that FTP errors should begin with a 4 or a 5 and the program FTP20C will catch those and report those types of errors. In reality, I've found a couple nuances to this approach. The first one is that if you have an incorrect system name to start the FTP, that error does not begin with a 4 or a 5. The second thing I've found, and I've only seen this when working with systems when one of them was not an AS/400, is that some errors that I would consider warnings show up in the error file. The FTP still completes normally, but an error is logged. Your options at that point are to change your FTP script to not generate the warning or monitor for it in your error-checking program (FTP20C).

Some information about the program

FTP10C is the program that creates the FTP script, does the FTP transfer and calls the error-monitoring program. I prefer to create the FTP script file (FILFTP) in qtemp so that multiple users can run this program at the same time without interfering with one another.

A description of the parms:

  • &PROCESS -- the name of your process so that you have something to refer to in case of an error
  • &FILE -- the file you want to transfer
  • &LCLDIR -- your local library or directory that you want to transfer to or from
  • &RMTDIR -- the library or directory on the target machine that you want to transfer to or from
  • &PUTGET -- P, G or D for a (P)ut, (G)et or a (D)elete
  • &SYSTEM -- the system name of your target machine. This can be an IP address or the name of an entry in your host table
  • &ERR -- This will be set to a 1 if an error is detected

FILFTP - FTP Input and output files 
A          R FTPFM
A            FTPDTA        80A         COLHDG('FTP COMMANDS')

FTP10C- FTP Create and process FTP script
PGM        PARM(&PROCESS &FILE &LCLDIR &RMTDIR &PUTGET +
                          &SYSTEM &ERR)
             DCL        VAR(&USER) TYPE(*CHAR) LEN(10)
             DCL        VAR(&PWD) TYPE(*CHAR) LEN(10)
             DCL        VAR(&PROCESS) TYPE(*CHAR) LEN(20) /* Name of +
                          process */
             DCL        VAR(&DTA) TYPE(*CHAR) LEN(80)
             DCL        VAR(&RMTDIR) TYPE(*CHAR) LEN(40)
             DCL        VAR(&LCLDIR) TYPE(*CHAR) LEN(40)
             DCL        VAR(&SYSTEM) TYPE(*CHAR) LEN(20)
             DCL        VAR(&BLKDTA) TYPE(*CHAR) LEN(80)
             DCL        VAR(&FILE) TYPE(*CHAR) LEN(40)
             DCL        VAR(&ERR) TYPE(*CHAR) LEN(1)
             DCL        VAR(&PUTGET) TYPE(*CHAR) LEN(1) /* DO A PUT, +
                          GET or Delete- "P" OR "G" or "D" */
             DCL        VAR(&DBLIB) TYPE(*CHAR) LEN(10)

 /* CREATE FTP SCRIPT FILES */
             RTVOBJD    OBJ(FILFTP) OBJTYPE(*FILE) RTNLIB(&DBLIB)

             CHKOBJ     OBJ(QTEMP/FILFTP) OBJTYPE(*FILE)
             MONMSG     MSGID(CPF9801 CPF3142) EXEC(DO)
               CRTDUPOBJ  OBJ(FILFTP) FROMLIB(&DBLIB) OBJTYPE(*FILE) +
                            TOLIB(QTEMP)
             ENDDO

             CHKOBJ     OBJ(QTEMP/FTPOUT) OBJTYPE(*FILE)
             MONMSG     MSGID(CPF9801 CPF3142) EXEC(DO)
               CRTDUPOBJ  OBJ(FILFTP) FROMLIB(&DBLIB) OBJTYPE(*FILE) +
                            TOLIB(QTEMP) NEWOBJ(FTPOUT)
             ENDDO

             CLRPFM     FILE(QTEMP/FILFTP)
             CLRPFM     FILE(QTEMP/FTPOUT)

  /* DO FTP */
             OVRDBF     FILE(FILFTP) TOFILE(QTEMP/FILFTP) MBR(*FIRST)
             OVRDBF     FILE(INPUT) TOFILE(QTEMP/FILFTP) MBR(*FIRST)
             OVRDBF     FILE(OUTPUT) TOFILE(QTEMP/FTPOUT) MBR(*FIRST)

  /* CREATE DYNAMIC FTP */
             RTVDTAARA  DTAARA(FTP1) RTNVAR(&USER)
             RTVDTAARA  DTAARA(FTP2) RTNVAR(&PWD)
             CHGVAR     VAR(&DTA) VALUE(&BLKDTA)
             CHGVAR     VAR(&DTA) VALUE(&USER *BCAT &PWD)
             CALL       PGM(FTP15R) PARM(&DTA)

             CHGVAR     VAR(&DTA) VALUE(&BLKDTA)
             CHGVAR     VAR(&DTA) VALUE('cd' *BCAT &RMTDIR)
             CALL       PGM(FTP15R) PARM(&DTA)

             CHGVAR     VAR(&DTA) VALUE(&BLKDTA)
             CHGVAR     VAR(&DTA) VALUE('lcd' *BCAT &LCLDIR)
             CALL       PGM(FTP15R) PARM(&DTA)

             CHGVAR     VAR(&DTA) VALUE(&BLKDTA)
             IF         COND(&PUTGET = 'D') THEN(CHGVAR VAR(&DTA) +
                          VALUE('del' *BCAT &FILE))
             IF         COND(&PUTGET = 'P') THEN(CHGVAR VAR(&DTA) +
                          VALUE('put' *BCAT &FILE))
             IF         COND(&PUTGET = 'G') THEN(CHGVAR VAR(&DTA) +
                          VALUE('get' *BCAT &FILE *BCAT '(replace'))
             CALL       PGM(FTP15R) PARM(&DTA)

             CHGVAR     VAR(&DTA) VALUE(&BLKDTA)
             CHGVAR     VAR(&DTA) VALUE('quit')
             CALL       PGM(FTP15R) PARM(&DTA)

             FTP        RMTSYS(&SYSTEM)
             CHGVAR     VAR(&ERR) VALUE(' ')
             CALL       PGM(FTP20C) PARM(&PROCESS &ERR)
 ENDPGM:
             DLTOVR     FILE(INPUT)
             MONMSG     MSGID(CPF0000)
             DLTOVR     FILE(OUTPUT)
             MONMSG     MSGID(CPF0000)
             ENDPGM


FTP200C- FTP Check for FTP errors
 PGM        PARM(&PROCESS &ERR)
             DCL        VAR(&MSG) TYPE(*CHAR) LEN(512)
             DCL        VAR(&BLKMSG) TYPE(*CHAR) LEN(512)
             DCL        VAR(&ERR) TYPE(*CHAR) LEN(1)
             DCL        VAR(&PROCESS) TYPE(*CHAR) LEN(20)
             DCLF       FILE(FILFTP)

             CHGVAR     VAR(&ERR) VALUE(' ')
             OVRDBF     FILE(FILFTP) TOFILE(QTEMP/FTPOUT)
 RCVF:
             RCVF
             MONMSG     MSGID(CPF0864) EXEC(GOTO CMDLBL(ENDPGM))
             IF         COND(%SST(&FTPDTA 1 1) *EQ '4' *OR +
                          %SST(&FTPDTA 1 1) *EQ '5') THEN(DO)
               CHGVAR     VAR(&ERR) VALUE('1')
               CHGVAR     VAR(&MSG) VALUE(&BLKMSG)
               CHGVAR     VAR(&MSG) VALUE('******' *BCAT +
                            &PROCESS *BCAT 'FTP PROCESS HAS STOPPED +
                            WITH THE FOLLOWING ERROR -' *BCAT &FTPDTA)
               SNDMSG     MSG(&MSG) TOUSR(*SYSOPR)
             ENDDO
             GOTO       CMDLBL(RCVF)
 ENDPGM:
             ENDPGM



FTP15R- Write FTP script records
A*****************************************************************
A*                                                               *
A*  Pgm Name...... FTP15R                                        *
A*  Description... CREATE DYNAMIC FTP DATA                       *
A*                                                               *
A*    *NOTE FILFTP IS OVERRIDEN BEFORE THIS PROGRAM IS CALLED    *
A*                                                               *
A*****************************************************************
FFILFTP  O   E                    DISK
C           *ENTRY    PLIST
C                     PARM           PDTA   80
C*
C                     MOVELPDTA      FTPDTA
C                     WRITEFTPFM
C*
C                     SETON                     LR

---------------------------
About the author: Tim is vice president of Technical Services at Interlink Technologies in Maumee, Ohio, where he serves as chief architect for their warehouse management system. He has worked in the banking, insurance, healthcare and distribution industries in various positions, including programmer/analyst, systems analyst and DP manager. Tim has worked on IBM midrange platforms since 1983.

==================================
MORE INFORMATION
==================================

  • Fast guide to Redbooks and articles on FTP for the iSeries
    Need information fast on FTP for the iSeries? Take a look at these publications. We've found Redbooks, articles and FAQs for everyone from novice users to experienced pros.
  • FTP tips you might not know about
    FTP is a necessity when transferring files to and from the iSeries. Site expert Tim Granatir provides a collection of miscellaneous FTP tips that address such subjects as the batch FTP process, logging FTP results to a file and getting to the Integrated File System. Check them out and see if there's anything you can add to your bag of tricks.
  • Webcast: iSeries FTP automation made easy
    There's no doubt that FTP is the most convenient communication tool on the iSeries. Being able to do a manual transfer here and there is good, but to get some real use out of this type of utility, you need to be able to program it and control it using table-driven variables. Thibault Dambrine shows you how easy it can be.
  • FTP products and vendors
    Looking for a tool to help you with FTP? Compare products in Search400.com's Product and Vendor Guide. Get information on products such as BlueZone--Terminal Emulation by Seagull Software, FTP Manager PGP Option by Patrick Townsend and Associates, PowerLock Security Suite for iSeries by SoftLanding Systems Inc. and ZMOD Exchange FTP by TrailBlazer Systems Inc.


This was first published in August 2003

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.