Janus FTP Server Sample Code: Upload to LOB: Difference between revisions
mNo edit summary |
mNo edit summary |
||
Line 1: | Line 1: | ||
As part of [[Janus Sockets]] Sirius provides an FTP Server. As described in the Janus Sockets Reference Manual, the server is based on set of Janus commands that define the behavior the server is to take when it receives connections from FTP clients. The basic behaviors of sending lists of files (really Model 204 procedures), and storing the same, is automated via the rules. But if you want to do something more complex, like stashing the uploaded content into a LOB field, you will have to intervene programmatically in the process. | As part of [[Janus Sockets]] Sirius provides an FTP Server. | ||
As described in the Janus Sockets Reference Manual, the server is based on a set of Janus commands that define the behavior the server is to take when it receives connections from FTP clients. The basic behaviors of sending lists of files (really Model 204 procedures), and storing the same, is automated via the rules. But if you want to do something more complex, like stashing the uploaded content into a LOB field, you will have to intervene programmatically in the process. | |||
This is an example of how you'd stash uploaded content in an LOB field. The steps are: | This is an example of how you'd stash uploaded content in an LOB field. The steps are: |
Revision as of 21:15, 28 January 2011
As part of Janus Sockets Sirius provides an FTP Server.
As described in the Janus Sockets Reference Manual, the server is based on a set of Janus commands that define the behavior the server is to take when it receives connections from FTP clients. The basic behaviors of sending lists of files (really Model 204 procedures), and storing the same, is automated via the rules. But if you want to do something more complex, like stashing the uploaded content into a LOB field, you will have to intervene programmatically in the process.
This is an example of how you'd stash uploaded content in an LOB field. The steps are:
- Define some receive rule via FTP ON.
- Override the STOR behavior with another FTP ON rule so it invokes a proc.
- The override automatically puts the uploaded file in the 0 proc, so...
- Use appendOpenProcedure to pull 0 into a stringlist.
- Put the stringList into a longString.
- Associate the longString with the universal buffer.
- Stash the buffer in the LOB.
First the rules. You define an FTP port like this:
* create FTP server on port 3205 JANUS DEFINE MYFTP 3205 FTPSERVER 4 CLIENTSOCKET FTPDCLIENT - AUDTERM PASVPORT 3001 BINDADDR 198.242.244.47 * Client port definition for active transfers JANUS DEFINE FTPDCLIENT * CLSOCK 5 REMOTE SOCKPMAX 5 JANUS CLSOCK FTPDCLIENT ALLOW * FTP access to MYPROC JANUS FTP MYFTP ASSIGN /MY TO FILE MYPROC JANUS FTP MYFTP ON /MY STOR OPEN FILE MYPROC CMD 'INCLUDE LOAD_TO_LOB' * Permissions JANUS FTP MYFTP ALLOW /MY WRITE TO USER JOE, JIM, BOB, JOHN * Set the home folder. JANUS FTP MYFTP HOME /MY TO ALL JANUS START MYFTP JANUS START FTPDCLIENT
The trick here is to assign a basic rule to load procedures to MYPROC, then to override the STOR behavior of that rule with ON rule that invokes a procedure -- in this case LOAD_TO_LOB, in file MYPROC.
The override of the STOR behavior tells the FTP server to stash the uploaded material in procedure 0. You then retrieve the contents of 0 into a stringlist, then into a longString and then to the LOB, like this:
OPEN FILE BLOBS Begin %len is float %x is float %sl is object stringList %bigString is longString %sl = New %x = $procOpn(0,'MYPROC') %sl:appendOpenProcedure %bigString = %sl:createLines $Lstr_Set_Userbuffer(%bigString) %len = $Lstr_Len(%bigString) myBlobFile: In BLOBS store record REC.TYPE = AB End Store Frn in myBlobFile ADD MYPICTURE=BUFFER,1,%len end for End