Kbase 20432: How to Transfer Files with FTP in Batch Mode on AS/400
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  1/26/2008 |
|
Status: Unverified
GOAL:
How to transfer files with FTP in batch mode on AS/400.
FIX:
To transfer multiple files from a remote host with a single CL command, follow these steps:
1) Make sure there is an FTP server running on the remote host.
2) Create a batch file that contains the desired FTP commands and
then use the CL program to process the batch file. Follow
these steps:
a) Create the source physical file FTPINOUT (or any name) with two members, FTPIN and FTPOUT.
Use the FTPIN member for valid FTP commands and FTPOUT
for logging all the messages within FTP session.
b) Execute the command CRTSRCPF FILE(Library/FTPINOUT).
c) Run WRKMBRPDM FILE(Library/FTPINOUT) and create 2 members
(F6 key)of the type *TXT. (Library can be almost anything.)
d) Edit the FTPIN member to add FTP commands. It
might look like the following:
User-id Password
NameFmt 1
GET ?..
GET ?..
GET ?..
QUIT
User-ID and password should be substituted by valid
values from the remote host. Use the "NameFMT 1" option
to include IFS for GET operations.
3) Create the following CL source code and compile it:
/* MYFTP */
/* CL program which runs batch FTP transfers using a command file */
PGM PARM(&host)
DCL VAR(&host) TYPE(*CHAR) LEN(32)
DCL VAR(&msg) TYPE(*CHAR) LEN(36)
DCL VAR(&count) TYPE(*DEC) LEN(3)
DCL VAR(&cmsg) TYPE(*CHAR) LEN(3)
DCLF FILE(Library/FTPINOUT)
OVRDBF FILE(FTPINOUT) TOFILE(Library/FTPINOUT) +
MBR(FTPOUT)
OVRDBF FILE(INPUT) TOFILE(Library/FTPINOUT) +
MBR(FTPIN)
OVRDBF FILE(OUTPUT) TOFILE(Library/FTPINOUT) +
MBR(FTPOUT)
CLRPFM FILE(Library/FTPINOUT) MBR(FTPOUT)
FTP RMTSYS(&host)
/* The loop and the status */
READ: RCVF
MONMSG MSGID(CPF0864) EXEC(GOTO CMDLBL(EOF))
CHGVAR VAR(&msg) VALUE(%SST(&srcdta 1 36))
IF COND(&msg *EQ '226 Transfer complete.') +
THEN(CHGVAR VAR(&count) +
VALUE(&count + 1))
GOTO CMDLBL(READ)
EOF: CHGVAR VAR(&cmsg) VALUE(&count)
SNDPGMMSG MSG('Number of files successfully
transfered + via FTP: ' || &cmsg)
ENDPGM
4) Create command source file and compile it:
/* MYFTP: */
/* Command source file for MYFTP program */
CMD PROMPT('Run batch FTP commands')
PARM KWD(HOST) TYPE(*CHAR) LEN(32) MIN(1) +
PROMPT('Host Name')