Using FTP in Batch Mode
FTP (File Transfer Protocol) can be used to transfer data from an MVS host to another MVS host. Although
it is commonly used interactively, FTP can be used to tranfer files in batch mode which allows unattended
file transfer. Here is an example of some JCL to do this.
//S2 EXEC PGM=FTP,REGION=2000K,DYNAMNBR=20,
// PARM='22.214.171.124 (EXIT'
//SYSPRINT DD SYSOUT=*
//OUTPUT DD SYSOUT=*
//NETRC DD DISP=SHR,DSN=&SYSUID..NETRC
//INPUT DD *
GET prof(isrprof) temp (REPLACE
The EXIT* option causes FTP to terminate on an error. It also causes the return code to be set if an error occurs.
In the example above, 126.96.36.199 is the IP address of the remote host. There must be an FTP server running on that host.
An existing dataset named userid.NETRC, where userid submitted this job, will be used to retrieve userid
and password information. Entries in this dataset look like:
000001 MACHINE 188.8.131.52 LOGIN user PASSWORD pswd
where user is the
userid for host 184.108.40.206 and pswd is the password. This eliminates the need to put the userid and password in the JCL.
The GET command moves data from the file prof on the foreign host (220.127.116.11) to the file temp on the
local host (the host where the batch job is running). A PUT command would move data the other way. Note
that the example above is based on Version 3.1 of the IBM TCP/IP product. Refer to the documentation for your TCP/IP
product for more information.
Setting Exit parameters in the real world.
//STEP0999 EXEC FTPBATCH,PARMS='ENTFTP (EXIT=8'
//NETRC DD DISP=SHR,DSN=XXXXX.XXXXX.XXXXXX.DATA
//INPUT DD DISP=SHR,DSN=XXXXX.XX.XXXX.CTLCARD(VMSWXFX3)
//* DIR XXXXXX.*
//* DIR *.dat
//* DELETE XXfuel.bku
//* PUT 'XXXXX.XXXXXXX.XXXX' XXXXXX.dat
Exit will return a RC of 8 if this step fails else FTP return code / 0 will be returned.
FTP EXIT return codes have the following format:
yy Represents the subcommand code, which is a number in the range 1–99. Each subcommand has an
EXIT_IF_ERROR flag that determines whether FTP is exited when an error occurs if you specified EXIT on the FTP command.
See Table 15 on page 91 for a description of the possible FTP subcommand codes.
xxx Represents the reply code that is sent from the server. The reply code is a 3-digit number. For a complete list of
FTPD reply codes see the OS/390 IBM Communications Server: IP and SNA Codes.
For example, the FTP EXIT return code 16550 indicates the following:
16 The GET command failed.
550 The reply code from the FTP server. The requested action was not taken; the file was not found or could not be
accessed. The assigned reply codes relating to FTP are:
000 Announcing FTP.
010 Message from system operator.
020 Exected delay.
030 Server availability information.
050 FTP commentary or user information.
100 System status reply.
110 System busy doing...
150 File status reply.
151 Directory listing reply.
200 Last command received correctly.
201 An ABORT has terminated activity, as requested.
202 Abort request ignored, no activity in progress.
230 User is "logged in". May proceed.
231 User is "logged out". Service terminated.
232 Logout command noted, will complete when transfer done.
233 User is "logged out". Parameters reinitialized.
250 FTP file transfer started correctly.
251 FTP Restart-marker reply.
Text is: MARK yyyy = mmmm
where 'yyyy' is user's data stream marker (yours)
and mmmm is server's equivalent marker (mine)
(Note the spaces between the markers and '=').
252 FTP transfer completed correctly.
253 Rename completed.
254 Delete completed.
257 Closing the data connection, transfer completed.
300 Connection greeting message, awaiting input.
301 Current command incomplete (no for long time).
330 Enter password.
331 Enter account (if account required as part of login sequence).
332 Login first, please.
400 This service not implemented.
401 This service not accepting users now, goodbye.
402 Command not implemented for requested value or action.
430 Log-on time or tries exceeded, goodbye.
431 Log-on unsuccessful. User and/or password invalid.
432 User not valid for this service.
433 Cannot transfer files without valid account. Enter account and
434 Log-out forced by operator action. Phone site.
435 Log-out forced by system problem.
436 Service shutting down, goodbye.
450 FTP: File not found.
451 FTP: File access denied to you.
452 FTP: File transfer incomplete, data connection closed.
453 FTP: File transfer incomplete, insufficient storage space.
454 FTP: Cannot connect to your data socket.
455 FTP: File system error not covered by other reply codes.
456 FTP: Name duplication; rename failed.
457 FTP: Transfer parameters in error.
500 Last command line completely unrecognized.
501 Syntax of last command is incorrect.
502 Last command incomplete, parameters missing.
503 Last command invalid (ignored), illegal parameter combination.
504 Last command invalid, action not possible at this time.
505 Last command conflicts illegally with previous command(s).
506 Last command not implemented by the server.
507 Catchall error reply.
550 Bad pathname specification (e.g., syntax error).
FTP codes and actions
The series code (the number) at the beginning of some lines of the FTP log describes the action
that took place between your computer and the server in the FTP process. The table below
describes these FTP codes and actions. Note: not all FTP servers will use the same codes.
100 Series Codes The requested action is being initiated, expect another reply before proceeding with a new command.
110 Restart marker reply.
120 Service ready in nnn minutes.
125 Data connection already open, transfer starting.
150 File status okay, about to open data connection.
200 Series Codes The requested action has been successfully completed.
200 Command okay.
202 Command not implemented, superfluous at this site.
211 System status, or system help reply.
212 Directory status.
213 File status.
214 Help message.
215 NAME system type. (Where NAME is an official system name from the list in the Assigned Numbers document.)
220 Service ready for new user.
221 Service closing control connection. Logged out if appropriate.
225 Data connection open; no transfer in progress.
226 Closing data connection. Requested file action successful (for example, file transfer or file abort).
227 Entering Passive Mode
230 User logged in, proceed.
250 Requested file action okay, completed.
257 "PATHNAME" created.
300 Series Codes The command has been accepted, but the requested action is being held in abeyance, pending receipt of further information.
331 User name okay, need password.
332 Need account for login.
350 Requested file action pending further information.
400 Series Codes The command was not accepted and the requested action did not take place, but the error condition is temporary and the action may be requested again.
401 This service is not accepting users now. User quota filled. Try again later.
421 Service not available, closing control connection. This may be a reply to any command if the service knows it must shut down.
425 Can't open data connection.
426 Connection closed; transfer aborted.
431 Log-in unsuccessful. User name and/or password invalid.
450 Requested file action not taken. File unavailable (e.g., file busy).
451 Requested action aborted: local error in processing.
452 Requested action not taken. Insufficient storage space in system.
453 File transfer incomplete. Insufficient storage space.
500 Series Codes The command was not accepted and the requested action did not take place.
500 Syntax error, command unrecognized. This may include errors such as command line too long.
501 Syntax error in parameters or arguments.
502 Command not implemented.
503 Bad sequence of commands.
504 Command not implemented for that parameter.
530 Not logged in.
532 Need account for storing files.
550 Requested action not taken. File unavailable (e.g., file not found, no access).
552 Requested file action aborted. Exceeded storage allocation (for current directory or dataset).
553 Requested action not taken. File name not allowed.
IBM Reference: http://publibz.boulder.ibm.com/epubs/pdf/f1aa2032.pdf.
Program Linkage Example:
05 LK-LNGTH PIC S9(4) COMP.
05 LK-TIME PIC 9(08).
PROCEDURE DIVISION USING LK-AREA.
* M A I N L I N E *
MOVE 'MAIN-LINE-PROCESS' TO WS-PROGRAM-LOCATION
*FTP steps without an EXIT command will ignore all FTP Errors, they will be displayed but will not stop FTP processing.
Sets the block mode. In block mode, data is transmitted as a series of data
blocks, preceded by one or more header bytes. Block mode preserves the
logical record boundaries of the data set or file. When Mode is set to B, the
data transfer type must be EBCDIC.
Specifying MOde B is equivalent to specifying the BLock subcommand.
Does a Windoze box support block mode?
I doubt it, since EBCDIC is required for block mode and Windoze is an ASCII system, not EBCDIC.
TYPE A and MODE B are mutually exclusive options
EZA1736I PUT 'DK037.W037DCLM.PXCAP310.DCLMCIAC.TXT' MONTHLY\DCLMCIAC.TXT
EZA1701I >>> SITE FIXrecfm 259 LRECL=259 RECFM=FB BLKSIZE=27972
500 'SITE FIXrecfm 259 LRECL=259 RECFM=FB BLKSIZE=27972': command not understood
You can also add a "SENDSITE" command immediately following your login to prevent the "500 'SITE FIXrecfm ...
command not understood" message.