kinda cool I did not know this:
article written by Thomas Snyder on MC Press Online
he has examples but i threw together a quick test script.
I see some uses for this..
article written by Thomas Snyder on MC Press Online
he has examples but i threw together a quick test script.
I see some uses for this..
Code:
*======================================================================= * PROGRAM - ##FTP * PURPOSE - FTP to a server get a list of files and retrive them * WRITTEN - * AUTHOR - * *======================================================================= d cmdstring s 2000 d cmdlength s 15 5 d ftpdata s 100 d Q s 1 inz('''') d remoteIP s 15 inz('XX.X.X.XX') d sqlstmt s 23000 varying d openList pr d FetchNext pr n d closeList pr // external calls d $command pr extpgm( 'QCMDEXC' ) d cmdstring 2000 options( *varsize ) const d cmdlength 15 5 const /free exsr $ftplist; exsr $readList; *inlr = *on; //------------------------------------------- // $ftpList - List the directory contents to // a table DIROUTPUT. // // if it doesnt exist system creates if there // then member is *Replaced.. //------------------------------------------- begsr $ftpList; // now copy the file to the IFS cmdstring = 'CPYTOIMPF FROMFILE(QTEMP/SLS28WORKP) ' + ' TOSTMF(' + Q + '/home/sls28/sls28.csv' + Q + ') ' + 'STMFCODPAG(*PCASCII) ' + 'RCDDLM(*CRLF) STRDLM(*NONE) MBROPT(*REPLACE)'; cmdlength = %len(%trim(cmdstring)); monitor; $command(cmdstring : cmdlength); on-error; endmon; //prepare the FTP //in case this is a repeat delete the overrides and //the input output file(s) cmdstring = 'DLTOVR INPUT'; cmdlength = %len(%trim(cmdstring)); monitor; $command(cmdstring : cmdlength); on-error; endmon; cmdstring = 'DLTOVR OUTPUT'; cmdlength = %len(%trim(cmdstring)); monitor; $command(cmdstring : cmdlength); on-error; endmon; cmdstring = 'DLTF FILE(QTEMP/INPUT)'; cmdlength = %len(%trim(cmdstring)); monitor; $command(cmdstring : cmdlength); on-error; endmon; cmdstring = 'DLTF FILE(QTEMP/OUTPUT)'; cmdlength = %len(%trim(cmdstring)); monitor; $command(cmdstring : cmdlength); on-error; endmon; cmdstring = 'CRTPF FILE(QTEMP/INPUT) ' + ' RCDLEN(256)'; cmdlength = %len(%trim(cmdstring)); monitor; $command(cmdstring : cmdlength); on-error; endmon; cmdstring = 'CRTPF FILE(QTEMP/OUTPUT) ' + ' RCDLEN(256)'; cmdlength = %len(%trim(cmdstring)); monitor; $command(cmdstring : cmdlength); on-error; endmon; // populate the input file Exec SQL INSERT INTO INPUT values('&user &password'); Exec SQL INSERT INTO INPUT values('dir (DISK '); Exec SQL INSERT INTO INPUT values('quit'); cmdstring = 'OVRDBF FILE(INPUT) TOFILE(QTEMP/INPUT)' + ' OVRSCOPE(*JOB) '; cmdlength = %len(%trim(cmdstring)); monitor; $command(cmdstring : cmdlength); on-error; endmon; cmdstring = 'OVRDBF FILE(OUTPUT) TOFILE(QTEMP/OUTPUT)' + ' OVRSCOPE(*JOB) '; cmdlength = %len(%trim(cmdstring)); monitor; $command(cmdstring : cmdlength); on-error; endmon; cmdstring = 'STRTCPFTP ' + Q + %trim(remoteIp) + Q ; cmdlength = %len(%trim(cmdstring)); monitor; $command(cmdstring : cmdlength); on-error; endmon; endsr; //------------------------------------------- // $readList - read the list created //------------------------------------------- begsr $readList; sqlstmt = 'select * from DIROUTPUT '; openList(); dow fetchNext(); // file date 1 8 // file time 11 17 // date&time 1 17 // isdirectory 25 29 // file size 29 38 // file name 40 89 // ..... 49 98 dsply %subst(ftpdata:40:25) ' '; enddo; closeList(); endsr; //------------------------------------------- /end-free *-------------------------------------------------------- * openList - Open a cursor to read file *-------------------------------------------------------- p openList b d openList pi /Free exec sql declare MyCursor cursor for statement; exec sql prepare statement from :sqlstmt; exec sql open mycursor; /End-Free p openList e *-------------------------------------------------------- * fetchNext - read one record at a time *-------------------------------------------------------- p fetchNext b d fetchNext pi n /free exec sql fetch next from mycursor into : ftpdata; if sqlstt < '02000'; return *on; else; return *off; endif; /end-free p fetchNext e *-------------------------------------------------------- * closeOrderList - Close the OrderHdr cursor *-------------------------------------------------------- p closeList b d closeList pi /free exec sql close MyCursor; /end-free p closeList e