在rexx中使用ftp有三种方法:
第一种是使用compound variable执行
第二种是使用stack执行
第二种是使用FTPAPI执行
下面就分别说一下这两种方法是如何实现的。
第一种
把要执行的ftp命令依次赋值给compound variable。具体例子如下:
"ALLOC F(FTPLOG) DS('C210408.FTP.LOG') OLD REUSE"
"ALLOC F(INPUT) UNIT(VIO) LRECL(80) SPACE(1) TRACKS RECFM(F B)"
"ALLOC F(OUTPUT) UNIT(VIO) LRECL(121) SPACE(1 10) CYLINDERS RECFM(V B)"
hostname = 'server ip'
input.1 = 'user pwd'
input.2 = 'bin'
input.3 = "get ptrlib/abc 'c210408.data.input' (replace"
input.4 = 'QUIT'
"EXECIO * DISKW INPUT (STEM INPUT. FINIS"
"FTP" hostname "(EXIT"
"EXECIO * DISKR OUTPUT (STEM OUTPUT. FINIS"
"EXECIO * DISKW FTPLOG (STEM OUTPUT. FINIS"
"FREE F(INPUT OUTPUT FTPLOG)"
此例子是把AS/400的pf数据复制到dataset里。并且把ftp的log写到C210408.FTP.LOG这个dataset。
第二种
使用stack和compound variable类似,具体例子如下:
"ALLOC F(FTPLOG) DS('C210408.FTP.LOG') OLD REUSE"
"ALLOC F(OUTPUT) UNIT(VIO) LRECL(121) SPACE(1 10) CYLINDERS RECFM(V B)"
hostname = 'server ip'
"newstack"
queue 'user'
queue 'pwd'
queue 'bin'
queue "get ptrlib/custom 'c210408.data.input' (replace"
queue 'QUIT'
"FTP" hostname "(EXIT"
"delstack"
"EXECIO * DISKR OUTPUT (FINIS STEM FTPO."
"EXECIO * DISKW FTPLOG (STEM FTPO. FINIS"
"FREE F(OUTPUT FTPLOG)"
第三种
在z/OS上ibm提供了ftpapi,我们可以用ftpapi来执行我们要的ftp命令。在网上可以搜索到例子,具体例子如下:
/* REXX */
/********************************************************************/
* Descriptive Name: REXX FTP Client API Sample */
/* */
/* */
/* Function: Sample FTP Client API for REXX language */
/* */
/* This sample does a directory list of the */
/* home directory. For a z/OS FTP server, this */
/* may be the the user's home directory in HFS */
/* or the user high level qualifier, depending */
/* on whether the server FTP.DATA has */
/* STARTDIRECTORY set to HFS or MVS™. */
/* */
/* It then does a directory search of /tmp and */
/* finds the largest file in /tmp. */
/* */
/********************************************************************/
/*********************************************************************/
/* Setup the constants for the FTPAPI invocations */
/*********************************************************************/
TRACEID = 'PAZ'
USER_COMMAND = 'user user1'
PASS_COMMAND = 'pass tcpsup'
DIR_COMMAND = 'dir *'
TMP_COMMAND = 'DIR /tmp/*'
OPENSTRING = '-w 300 127.0.0.1 21 '
ENVVAR1 = '_CEE_DMPTARG=/tmp'
ENVVAR2 = '_BPX_JOBNAME=MYJOB'
/*********************************************************************/
/* Initialize the FCAI stem. */
/*********************************************************************/
if ftpapi('fcai.', 'create', TRACEID) < 0 then do
Say 'Unable to create the FCAI'
exit -1
end
/*********************************************************************/
/* Turn on tracing of the Client API tracing. This is a different */
/* trace from the REXX FTP Client API trace and is always written */
/* to SYSOUT. */
/*********************************************************************/
if ftpapi('fcai.', 'set_trace', 'ON') < 0 then do
call ftp_error 'fcai.'
end
/*********************************************************************/
/* Initialize the FTP client environment and open a connection */
/* to the FTP server using the OPENSTRING. Two environment */
/* variables are also provided to the FTP Client API to be used */
/* when intitializing its environment. */
/*********************************************************************/
if ftpapi('fcai.', 'init', OPENSTRING, ENVVAR1, ENVVAR2) < 0 then do
call ftp_error 'fcai.'
end
/*********************************************************************/
/* Sign on */
/* Enter the userid. */
/*********************************************************************/
if ftpapi('fcai.', 'scmd', USER_COMMAND, 'W') < 0 then do
call ftp_error 'fcai.'
end
/*********************************************************************/
/* If the FTP server prompts for a password, provide one. In some */
/* instances, an FTP server may not prompt for a password (e.g., */
/* when an anonymous user logs on to some FTP servers). */
/*********************************************************************/
if fcai.FCAI_Result = FCAI_RESULT_PROMPTPASS then do
if ftpapi('fcai.', 'scmd', PASS_COMMAND, 'W') < 0 then do
call ftp_error 'fcai.'
end
end
/*********************************************************************/
/* List directory entries */
/* Enter a subcommand DIR_COMMAND to retrieve a listing of all files */
/* in the directory. The REXX program requests the FTP client */
/* API wait for the subcommand to complete before returning. */
/*********************************************************************/
if ftpapi('fcai.', 'scmd', DIR_COMMAND, 'W') < 0 then do
call ftp_error 'fcai.'
end
/*********************************************************************/
/* Fetch the lines returned by the DIR subcommand. */
/*********************************************************************/
if ftpapi('fcai.', 'getl_copy', 'lines.', 'L') < 0 then do
call ftp_error 'fcai.'
end
/*********************************************************************/
/* Display the results of the output. lines.0 contains the total */
/* number of lines returned, while lines.1...lines.n contains the */
/* output for each individual line. */
/*********************************************************************/
say 'Directory output is:'
do i=1 to lines.0
say ' 'lines.i
end
/*********************************************************************/
/* Find the largest file in /tmp */
/* Do a DIR of /tmp in non-wait mode, find the largest file in the */
/* directory. The FTP client will return immediately, even if */
/* the subcommand has not completed. The POLL request is then */
/* used to determine when the subcommand has completed. */
/*********************************************************************/
if ftpapi('fcai.', 'scmd', TMP_COMMAND, 'N') < 0 then do
call ftp_error 'fcai.'
end
/*********************************************************************/
/* Poll to see when the DIR is done. */
/* */
/* If running under USS/OMVS, make sure that syscalls are not */
/* enabled prior to making the first CREATE request. Enabling */
/* syscalls makes the USS/OMVS environment variables no longer */
/* available to the REXX program, so the REXX FTP Client API would */
/* be unable to read the FTP_REXX_TRACE_FILE environment variable */
/* (if provided) once syscalls are enabled. */
/*********************************************************************/
call syscalls "ON" /* Enable SYSCALLS */
if ftpapi('fcai.', 'poll') < 0 then do
call ftp_error 'fcai.'
end
do while fcai.fcai_result = FCAI_RESULT_INPROGRESS
address syscall 'sleep 20'
if ftpapi('fcai.', 'poll') < 0 then do
call ftp_error 'fcai.'
end
end
/*********************************************************************/
/* find the largest file */
/* Each line of output of a DIR command appears as: */
/* drwxrwxrwx cnt userid groupid size date file */
/*********************************************************************/
largest_file = ""
largest_file_size = 0
if ftpapi('fcai.', 'getl_find', 'lines.', 'L', 'F') < 0 then do
call ftp_error 'fcai.'
end
/*********************************************************************/
/* Continue to search until there are no more lines. When there */
/* is no matching line, the REXX FTP Client API returns a result */
/* of FCAI_RESULT_NOMATCH and sets lines.0 to 0. */
/*********************************************************************/
do until lines.0 = 0
parse var lines.1 dirinfo count userid groupid size date file .
if size > largest_file_size then do
largest_file = lines.1
largest_file_size = size
end
if ftpapi('fcai.', 'getl_find', 'lines.', 'L', 'N') < 0 then do
call ftp_error 'fcai.'
end
end
if largest_file <> "" then do
say 'Characteristics of the largest file are'
say ' 'largest_file
end
else do
say 'No files found'
end
/*********************************************************************/
/* Enter the QUIT subcommand and terminate the connection. */
/* It's better to enter the QUIT subcommand before entering the */
/* ftpapi('term') command. In this way, any error traces can be */
/* displayed. */
/*********************************************************************/
if ftpapi('fcai.', 'scmd', 'QUIT', 'W') < 0 then do
call ftp_error 'fcai.'
end
/*********************************************************************/
/* Enter the TERM request to close this instance of the FTP client */
/* API. */
/*********************************************************************/
if ftpapi('fcai.', 'term') < 0 then do
Say "Unexpected error on ftpapi('term')"
exit -1
end
exit
第三种例子和前两种不同的是不能输入ftp log到指定的dataset中(不知道有没有,我没有找到,呵呵)。
不过可以得到trace信息。操作步骤如下:
首先要执行如下的ftpapi,这样才能得到trace信息。
if ftpapi('fcai.', 'set_trace', 'ON') < 0 then do
call ftp_error 'fcai.'
end
其次,默认的情况会产生一个名叫FTPRXTRC的ddname中,但需要alloc一个具体的dataset,操作如下:
ALLOC FILE(FTPRXTRC) DA(FTP.TRACE.OUT) NEW LRECL(80) RECFM(F B) TRACK SPACE(10 10)
更多关于ftpapi的信息请参照《IP Programmer’s Guide and Reference》书号为SC31-8787-12
欢迎拍砖。。。。
阅读(2955) | 评论(0) | 转发(0) |