Using FTP from CL is easy, but it isn't so easy to determine if a transfer succeeded. Different FTP servers use different response codes, and the responses are buried in English-text output. The FTP results program is my solution.
The program simply scans the OUTPUT file for the specified string and returns the number of times it occurs. It uses embedded SQL to do the search with wildcards and forced capitalization, simplifying the process.
&search is character 50; found is decimal 6,0. CHGVAR VAR(&SEARCH) VALUE('226 transfer complet') CALL PGM(FTPRESULTS) PARM(&SEARCH FOUND) IF COND(FOUND *eq 1) then(do) (complete sample in code) I found the "226 transfer complet" string and the number of times it should appear by looking at the output of the last successful transfer. FTP results SQL RPGLE: ------------------------ * Scan the OUTPUT file for the string specified by SEARCHSTSTR, * returning the number of times found in COUNT. * Use OVRDBF to point OUTPUT at the correct member of file FTP * Spaces are replaced with wild cards. Data forced to upper case. * ex: dcl &search *char 50 '226 transfer complete' * dcl found *dec (6 0) * call ftpresults (&search found) * or * call 'ftpresults' * parm string 50 * parm #found 6 0 * d UPPER c const('ABCDEFGHIJKLMNOPQRSTUVWXYZ') d lower c const('abcdefghijklmnopqrstuvwxyz') d Search s 50 varying c if %parms = 2 C *entry plist C parm searchstr 50 C parm count 6 0 c eval search='%'+%trim(searchstr)+'%' c ' ':'%' xlate search search c lower:UPPER xlate search search c/exec sql c+ select count(*) into :COUNT from OUTPUT c+ where upper(srcdta) like :SEARCH c/end-exec c endif c return -------------- Sample CL pgm dcl &search *char 50 dcl found *dec (6 0) clrpfm file(ftp) mbr(billzipO) ovrdbf input tofile(ftp) mbr(billzipI) ovrdbf output tofile(ftp) mbr(billzipO) ftp rmtsys('FTP.SERVICEBUREAU.COM') CHGVAR VAR(&SEARCH) VALUE('226 transfer complet') CALL PGM(FTPRESULTS) PARM(&SEARCH FOUND) IF COND(FOUND *ne 1) then(do) sndmsg msg('Billzip ftp failed') tousr(*sysopr) enddo endpgm
================================== MORE INFORMATION ON THIS TOPIC ==================================
The Best Web Links: tips, tutorials and more.
Ask your programming questions--or help out your peers by answering them--in our live discussion forums.
Ask the Experts yourself: Our application development gurus are waiting to answer your programming questions.
This was first published in May 2003