Janus FTP Server Sample Code: Upload to LOB

From m204wiki
Jump to navigation Jump to search

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:

  1. Define some receive rule via FTP ON.
  2. Override the STOR behavior with another FTP ON rule so it invokes a proc.
  3. The override automatically puts the uploaded file in the 0 proc, so...
  4. Use appendOpenProcedure to pull 0 into a stringlist.
  5. Put the stringList into a longString.
  6. Associate the longString with the universal buffer.
  7. 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) %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