Вы находитесь на странице: 1из 4

*======================================================================= * 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 d FetchNext d closeList pr pr pr n

// external calls d $command pr d cmdstring d cmdlength /free exsr $ftplist; exsr $readList; *inlr = *on;

extpgm( 'QCMDEXC' ) 2000 options( *varsize ) const 15 5 const

//------------------------------------------// $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 Exec SQL INSERT INTO INPUT values('&user &password'); INSERT INTO INPUT values('dir (DISK '); INSERT INTO INPUT values('quit');

Exec SQL

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 file time date&time isdirectory file size file name ..... 1 11 1 25 29 40 49 8 17 17 29 38 89 98

dsply %subst(ftpdata:40:25) ' '; enddo; closeList(); endsr; //------------------------------------------/end-free *-------------------------------------------------------* openList - Open a cursor to read file *-------------------------------------------------------p openList b d openList /Free pi

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 /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 /free exec sql close MyCursor; /end-free p closeList e pi pi n

Вам также может понравиться