IBM Support

Batch FTP - Examples

Technote (troubleshooting)


Problem(Abstract)

This document contains examples of a successful and unsuccessful batch FTP.

Resolving the problem

Batch FTP: A Simple Example

The following is a simple example of a batch file transfer involving the successful transfer of one file from a remote system and the unsuccessful transfer of one file from a remote system.


The components are as follows:

o The CL program.
o The Input Commands File (an input file of FTP commands, MAX record length of 2000) - member type should be TXT.
o The Output Messages File (an output file of FTP messages) - member type should be TXT.

The CL Program

************************************************************
     ITSOLIB2/QCLSRC BATCHFTP:
     ----------------------
         PGM
         OVRDBF   FILE(INPUT) TOFILE(ITSOLIB2/QCLSRC) MBR(FTPCMDS)
         OVRDBF   FILE(OUTPUT) TOFILE(ITSOLIB2/QCLSRC) MBR(OUT)
         FTP      RMTSYS(SYSxxx)
         ENDPGM
     ************************************************************



The BATCHFTP program overrides the INPUT parameter to the source physical file ITSOLIB2/QCLSRC MBR(FTPCMDS). The output is sent to MBR(OUT).

The Input Commands File (member type should be TXT)

 ************************************************************
     ITSOLIB2/QCLSRC FTPCMDS:
     ---------------------
     ITSO ITSO
     CD ITSOLIB1
     SYSCMD CHGCURLIB ITSOLIB2
     GET QCLSRC.BATCHFTP QCLSRC.BATCHFTP (REPLACE
     QUIT
     ************************************************************



The FTP subcommands required are shown in the FTPCMDS file.

The Output Messages File (member type should be TXT)
 
************************************************************
     FTP Output Redirected to a File
     FTP Input from Overridden File
     Connecting to host name SYSxxx
     at address x.xxx.xx.xxx using port 21.
     220-QTCP at SYSxxx.rchland.ibm.com.
     220 Connection will close if idle more than 5 minutes.
     215  OS/400 is the remote operating system.
          The TCP/IP version is "V3R1M0"
     Enter login ID (itso):
     > ITSO ITSO
     331 Enter password.
     230 ITSO logged on.
     250  Now using naming format "0".
     257 "QGPL" is current library.
     Enter an FTP subcommand.
     > CD ITSOLIB1
     Enter an FTP subcommand.
     250 Current library changed to ITSOLIB1.
     > SYSCMD CHGCURLIB ITSOLIB2
     Enter an FTP subcommand.
     > GET QCLSRC.BATCHFTP QCLSRC.BATCHFTP (REPLACE
     200 PORT subcommand request successful.

      150 Retrieving member BATCHFTP in file QCLSRC in library ITSOLIB1.
     250 File transfer completed successfully.
     147 bytes transferred in 0.487 seconds. Transfer rate 0.302 KB/sec.
     Enter an FTP subcommand.
     > QUIT
     221 QUIT subcommand received.
     ************************************************************



The output file is shown. It is a straightforward matter to write a program to process this file and display an error message on QSYSOPR message queue if there are any error messages. FTP error messages have numbers that start with a 4 or 5.

FTP in Batch Mode: A Complex Example

The following example shows how to retrieve files from several remote hosts to a central IBM OS/400 or IBM i5/OS system in batch mode:


 |----------|
    |AS/400    |
    |RCHAS149  |
    |SNA node  |-----|
    |OS/400 or |     |
    |V2R3      |     |
    |          |     |
    |----------|     |
    |----------|     |       |----------|
    |AS/400    |     |       |AS/400    |
    |RCHASM02  |     |       |RCHRS001  |
    |9.4.73.250|     |       |9.4.73.198|
    |OS/400    |     |       |IBM® AIX® |
    |V3R1      |     |       |V3.2.3    |
    |          |     |       |          |
    |-----|----|     |       |-|--------|
          |          |         |
        |-|----------|---------|------|
        |   IBM Rochester IP Network  |
        ||------------------------|---|
         |                        |
         |                        |
   |-----|----|             |-----|------|
   |AS/400    |             | DEC        |
   |RCHASM03  |             | Microvax   |
   |9.4.73.212|             | 3100       |
   |OS/400    |             | MVAX       |
   |V3R1      |             | 9.4.6.252  |
   |          |             | VMS 5.5    |
   |----------|             | WIN/TCP    |
                            | Wollongong |
                            |------------|



  Figure 8-31. Network Example for Batch FTP


User GWIL on OS/400 or i5/OS RCHASM03 wants to do the following:
1. Retrieve files from hosts RCHRS001 (RS/6000) and MVAX (VAX).
2. After retrieving the file from RCHRS001, the file should be transferred to RCHASM02 (another IBM iSeries family of servers system) using FTP.
3. From there, the file is to be sent using SNA to OS/400 or i5/OS RCHAS149.

Create a CL Program to Start FTP

To create a CL program to start FTP, do the following:
1. As we have seen in the previous example, FTP uses the display station for command INPUT and message OUTPUT, and this needs to be overridden for use in batch mode. We use the OVRDBF command to overwrite these files with the ones to be used in batch. On the operating system command line, type the following:

OVRDBF FILE(INPUT) TOFILE(GERRYLIB/QCLSRC) +
MBR(FTPCMDS)

Press the Enter key. Then, type the following:

OVRDBF FILE(OUTPUT) TOFILE(GERRYLIB/QCLSRC) +
MBR(FTPLOG)


Press the Enter key.
2. A host name or an Internet address is a required parameter for the STRTCPFTP command that is included in the CL program file. However, if one wants to specify the remote systems in the input commands file instead of the CL program file, then a dummy host name must be specified for the STRTCPFTP command to satisfy the required syntax. This dummy name may be a fictitious host name or a real host name. If it is a real name, the first entry in the input commands file must be a user ID and a password, and the second entry must be the CLOSE subcommand. If it is not a real host name, these entries are not required, and the first entry should be an OPEN subcommand to connect to the desired server system.

FTP RMTSYS(LOOPBACK)

FTP processes the input file and writes messages to the output file (FTPLOG).
3. After the FTP application ends, delete the overrides. On the operating system command line, type the following:

DLTOVR FILE(INPUT OUTPUT)

Press the Enter key.

The CL program for batch FTP will look like the following example on system RCHASM01:
Columns . . . :    1  71           Browse                      GERRYLIB/QCLSRC  
   

 
     SEU==>                                                                FTPBATCH  
     FMT **  ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7    
            *************** Beginning of data *************************************  
    0001.00 PGM                                                                      
    0002.00              OVRDBF     FILE(INPUT) TOFILE(GERRYLIB/QCLSRC) +            
    0003.00                           MBR(FTPCMDS)                                    
    0004.00              OVRDBF     FILE(OUTPUT) TOFILE(GERRYLIB/QCLSRC) +            
    0005.00                           MBR(FTPLOG)                                    
    0006.00              FTP        RMTSYS(LOOPBACK) /* (FTP CL Program) */          
    0007.00              DLTOVR     FILE(INPUT OUTPUT)                                
    0008.00 ENDPGM                                                                    
            ****************** End of data ****************************************  
                                                                                     
                                                                                             





      F3=Exit   F5=Refresh   F9=Retrieve   F10=Cursor   F12=Cancel                    
     F16=Repeat find        F24=More keys

Create the FTP Input File (FTCPDMS)

This file must contain all the FTP client subcommands necessary to connect and log on to the server, set up for and do the file transfers, close the server connection, and end the client session. The example, the following figure, shows the subcommands used for transferring files to two different remote systems.

Columns . . . :    1  71           Browse                      GERRYLIB/QCLSRC  
     SEU==>                                                                 FTPCMDS  
     FMT **  ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7    
            *************** Beginning of data *************************************  
    0001.00 gwil ****                                                                
    0002.00 close                                                                    
    0003.00 open rchrs001                                                            
    0004.00 user root root                                                            
    0005.00 ascii                                                                    
    0006.00 syscmd dltf file(gerrylib/rs6)                                            
    0007.00 get /Itsotest gerrylib/rs6.rs6                                            
    0008.00 close                                                                    
    0009.00 open mvax                                                                
    0010.00 user tester tester                                                        
    0011.00 get screen1.file gerrylib/vax.vax (replace                                
    0012.00 close                                                                    
    0013.00 open rchasm02                                                            
    0014.00 user gwil ****                                                            
    0015.00 ebcdic                                                                    
    0016.00 put gerrylib/rs6.rs6 gerrylib/rs6.rs6                                    

     0017.00 quote rcmd sndnetf file(gerrylib/rs6) tousrid((gwil rchas149))            
    0018.00 close                                                                    
    0019.00 quit                                                                      
            ****************** End of data ****************************************  
     F3=Exit   F5=Refresh   F9=Retrieve   F10=Cursor   F12=Cancel                    
     F16=Repeat find        F24=More keys

The explanation for the FTP client subcommands as shown in the above figure follows. The line numbers on the display correspond to the numbers that follow.

0001 User ID and password for dummy connection within client OS/400 RCHASM03.

0002 Close dummy connection in OS/400 RCHASM03.

0003 Open control connection to RISC System/6000 RCHRS001.

0004 USER subcommand with user ID and password for RCHRS001.

Note: When running FTP in batch mode, the USER subcommand must follow an OPEN subcommand. Both the logon user ID and password parameters for the USER subcommand should be provided. This is different when operating FTP interactively online. When FTP is run interactively online, then the client will automatically initiate a USER subcommand and prompt you for a logon ID. There is no automatic USER subcommand when running FTP in batch mode.

0005 Transfer ASCII data (will be translated on OS/400 to/from EBCDIC).

0006 CL command to be run on client OS/400 or i5/OS: delete file. Instead parameter (REPLACE) could be used with the next statement.

0007 Retrieve file from RISC System/6000 system

0008 Close control connection to RISC System/6000 RCHRS001.

0009 Open connection to VAX MVAX.

0010 USER subcommand with user ID and password for MVAX.

0011 Retrieve file from VAX replacing existing OS/400 or i5/OS file.

0012 Close control connection to VAX MVAX.

0013 Open control connection to remote OS/400 or i5/OS RCHASM02.

0014 USER subcommand with user ID and password for RCHASM02.

0015 Transfer EBCDIC data (as it is from OS/400 or i5/OS to OS/400 or i5/OS).

0016 Send OS/400 or i5/OS file to OS/400 or i5/OS RCHASM02 with TCP/IP.

0017 Send this file from server OS/400 or i5/OS RCHASM03 to remote OS/400 or i5/OS RCHAS149 through SNA network.

0018 Close control connection to OS/400 or i5/OS RCHASM02.

0019 End FTP application.


Create CL Program for Submitting the FTPBATCH Job

To schedule the file transfers and run them unattended, create a CL program that submits the FTPBATCH job. In the figure below, the file transfers are supposed to run the next Friday, 17:00 hour, in unattended mode.


 Columns . . . :    1  71           Browse                      GERRYLIB/QCLSRC  
     SEU==>                                                               FTPSUBMIT  
     FMT **  ...+... 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7    
            *************** Beginning of data *************************************  
    0001.00 PGM                                                                      
    0002.00              SBMJOB     CMD(CALL PGM(GERRYLIB/FTPBATCH)) +                
    0003.00                           JOB(FTPFRIDAY) OUTQ(QUSRSYS/GERRYQ)    +        
    0004.00                           SCDDATE(*FRI) SCDTIME(170000) /* FTP for +      
    0005.00                           Friday, 5:00 in the afternoon */                
    0006.00 ENDPGM                                                                    
            ****************** End of data ****************************************  
                                                                                     
     



      F3=Exit   F5=Refresh   F9=Retrieve   F10=Cursor   F12=Cancel                    
     F16=Repeat find        F24=More keys

Check the FTP Output File for Errors

While running at the scheduled time, FTP creates the data in file member FTPLOG shown in the figure below. The data in file member FTPLOG corresponds to original statements found in the figures above.


   Connecting to host name LOOPBACK at address 127.0.0.1 using port 21.    
       220-QTCP at localhost.                                                          
      220 Connection will close if idle more than 5 minutes.                          
      215  OS/400 is the remote operating system. The TCP/IP version is "V3R1M0".    
      Enter login ID (gwil):                                                          
                                                                                     
      >>>GWIL ****                                                                    
      331 Enter password.                                                            
      230 GWIL logged on.                                                            
      250 Now using naming format "0".                                                
      257 "QGPL" is current library.                                                  
      Enter an FTP subcommand.                                                        
                                                                                     
      > CLOSE                                                                        
      221 QUIT subcommand received.                                                  
      Enter an FTP subcommand.                                                        
                                                                                     
      > OPEN RCHRS001                                                                
      Connecting to host name RCHRS001 at address 9.4.73.198 using port 21.          
      220 rchrs001.rchland.ibm.com FTP server (Version 4.9 Thu Sep 2 20:35:07 CDT    
          1993) ready.                                                                
      215 UNIX Type:L8 Version: BSD-44                                                
      Enter an FTP subcommand.

> USER root ****                                                                
      331 Password required for root.                                                
      230 User root logged in.                                                        
      Enter an FTP subcommand.                                                        
                                                                                     
      > ASCII                                                                        
      200 Type set to A; form set to N.                                              
      Enter an FTP subcommand.                                                        
                                                                                     
      > SYSCMD DLTF FILE(GERRYLIB/RS6)                                                
      Enter an FTP subcommand.                                                        
                                                                                     
      > GET /Itsotest GERRYLIB/RS6/RS7                                                
      200 PORT command successful.                                                    
      150 Opening data connection for /Itsotest (467 bytes).                          
      226 Transfer complete.                                                          
      467 bytes transferred in 2.845 seconds. Transfer rate 0.167 KB/sec.            
      Enter an FTP subcommand.
FTP Output (FTPLOG) after Running FTPBATCH Program (Part 1)


> USER root ****                                                                
      331 Password required for root.                                                
      230 User root logged in.                                                        
      Enter an FTP subcommand.                                                        
                                                                                     
      > ASCII                                                                        
      200 Type set to A; form set to N.                                              
      Enter an FTP subcommand.                                                        
                                                                                     
      > SYSCMD DLTF FILE(GERRYLIB/RS6)                                                
      Enter an FTP subcommand.                                                        
                                                                                     
      > GET /Itsotest GERRYLIB/RS6/RS7                                                
      200 PORT command successful.                                                    
      150 Opening data connection for /Itsotest (467 bytes).                          
      226 Transfer complete.                                                          
      467 bytes transferred in 2.845 seconds. Transfer rate 0.167 KB/sec.            
      Enter an FTP subcommand.
FTP Output (FTPLOG) after Running FTPBATCH Program (Part 2)


> CLOSE                                                                        
      221 Goodbye.                                                                    
      Enter an FTP subcommand.                                                        
                                                                                     
      > OPEN MVAX                                                                    
      Connecting to host system mvax at address 9.4.6.252 using port 21.              
      220 FTP Service Ready                                                          
      Enter an FTP subcommand.                                                        
                                                                                     

  |    > USER TESTER ******                                                            
      331 User name TESTER received, please send password                            
      230 TESTER logged in, directory $DISK1:^TESTER║                                
      Enter an FTP subcommand.                                                        
                                                                                     
      GET SCREEN1.FILE GERRYLIB/VAX.VAX (REPLACE                                      
      200 PORT Command OK.                                                            
      125 ASCII transfer started for $DISK1:^TESTER║SCREEN1.FILE;1(266586 bytes)      
      226 File transfer completed ok.                                                
      265037 bytes transferred in 8.635 seconds. Transfer rate 30.694 KB/sec.        
      Enter an FTP subcommand.                                                        
                                                                                     
      > CLOSE                                                                        
      221 Goodbye.                                                                    
      Enter an FTP subcommand.                                                        
                                                                                     
      OPEN RCHASM02                                                                  
      Connecting to host system RCHASM02 at address 9.4.73.250 using port 21.        
      220-QTCP at RCHASM02.rchland.ibm.com.                                          
      220 Connection will close if idle more than 5 minutes.                          
      215  OS/400 is the remote operating system. The TCP/IP version is "V3R1M0".    
            Enter an FTP subcommand.
FTP Output (FTPLOG) after Running FTPBATCH Program (Part 3)


> USER GWIL ****                                                                
      331 Enter password.                                                            
      230 GWIL logged on.                                                            
      250 Now using naming format "0".                                                
      257 "QGPL" is current library.                                                  
      Enter an FTP subcommand.                                                        
                                                                                     
      > EBCDIC                                                                        
      200 Representation type is EBCDIC nonprint.                                    
      Enter an FTP subcommand.                                                        
                                                                                     
      > PUT GERRYLIB/RS6.RS6 GERRYLIB/RS6.RS6                                        
      200 PORT subcommand request successful.                                        
      150 Sending file to member RS6 in file RS6 in library GERRYLIB.                
      250 File transfer completed successfully.                                      
      467 bytes transferred in 0.148 seconds. Transfer rate 3.146 KB/sec.            
      Enter an FTP subcommand.                                                        
                                                                                     
      > RCMD SNDNETF FILE(GERRYLIB/RS6) TOUSRID((GERRYLIB RCHAS149))                  
      250 Command SNDNETF FILE(GERRYLIB/RS6) TOUSRID((GWIL RCHAS149))                
          successful.                                                                
      Enter an FTP subcommand.
FTP Output (FTPLOG) after Running FTPBATCH Program (Part 4)


> CLOSE                                                                        
      221 QUIT subcommand received.                                                  
      Enter an FTP subcommand.                                                        
      > QUIT                                                                          
      (This ends the FTP application)
FTP Output (FTPLOG) after Running FTPBATCH Program (Part 5)


This output should be checked for errors that might have occurred during FTP processing. This can be done by you visually checking or by a program testing for error reply codes. Three-digit FTP error reply codes start with 4 or 5. A list of FTP reply codes is detailed in Chapter 10 of the TCP/IP Configuration and Reference manual (SC41-3420-04). Be careful to avoid messages such as '467 bytes transferred...'

Sample Procedure: A sample REXX procedure and a sample physical file member are shipped as part of the TCP/IP product. File QATMPINC in library QTCP includes the following members:
o BATCHFTP that contains REXX source code to specify the input and output batch files, and start FTP.
o BFTPFILE that contains the subcommands and data required for logon and running FTP.

Historical Number

9245851

Document information

More support for: IBM i
Communications-TCP

Software version: Version Independent

Operating system(s): IBM i

Reference #: N1010065

Modified date: 08 May 2013


Translate this page: