Home > AS/400 Tips > iSeries programmer tips > Dynamically transfer files via FTP
iSeries 400 Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ISERIES PROGRAMMER TIPS

Dynamically transfer files via FTP


Tim Granatir, Search400.com expert
08.27.2003
Rating: -4.35- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


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.


Rate this Tip
To rate tips, you must be a member of Search400.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
RPG iSeries programming
Enhancing RPG with external SQL stored procedures
Introduction to SQLRPGLE on IBM i: Making a report
Making the most of RPG data handling on IBM i
IBM i shop boosts online sales with RPG-based Web platform
Migrating from RPG to EGL on IBM i
Allow access to data from a stored procedure result set using COBOL or RPG
EGL Rich UI on IBM i: Do you Dojo?
Programming for the Web on the IBM i, what is possible
A taste of COMMON: ILE, IBM releases, Web applications and new products
Documenting nested program structures on the AS/400

iSeries programmer tips
Enhancing RPG with external SQL stored procedures
Tracking data changes on IBM i with triggers
Introduction to SQLRPGLE on IBM i: Making a report
Implementing a browser interface in COBOL: Displaying database fields
Taking advantage of CL advancements, starting with V5R3
TAATOOL: Useful tools for programmers on IBM i
Implementing a browser interface in COBOL: Creating your graphic Web page
Implementing a browser interface in COBOL: Getting started
Making the most of RPG data handling on IBM i
Groovy programming on IBM i

Application Development
iSeries calling an .exe
Top 10 programmer tips
Formatted work job scheduler
Convert system date and time
Mixing free format code with embedded SQL
SQL update a field in one file from a field in another file
Webcasts for iSeries programmers
Programming advice from the pros
Easy code copying via the drag and drop method
Setting FTP time-outs

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
Report Program Generator  (Search400.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

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.



iSeries Security - Security Tools, Physical Security and System Security
HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts