Janus FTP Server Sample Code: Upload to LOB: Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (Created page with " 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 beh...")
 
m (1 revision)
 
(4 intermediate revisions by one other user not shown)
Line 1: Line 1:
As part of [[Janus Sockets]] Sirius provides an FTP Server. 


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 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 a LOB.  The steps are:
This is an example of how you'd stash uploaded content in an LOB field.  The steps are:


<ol>
<ol>
Line 38: Line 39:
</p>
</p>


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 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:
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:


<p class="code">
<p class="code">
PROCEDURE LOAD_TO_LOB
  OPEN FILE BLOBS
  OPEN FILE BLOBS


Line 53: Line 53:


   %sl = New
   %sl = New
   %x  = $procOpn(0,'MYPROC')
   %x  = $procOpn(0)
   %sl:appendOpenProcedure
   %sl:appendOpenProcedure
   %bigString = %sl:createLines
   %bigString = %sl:createLines
Line 68: Line 68:
   end for
   end for
  End
  End
END PROCEDURE LOAD_TO_LOB
</p>
</p>

Latest revision as of 22:02, 30 October 2012

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