Kbase 21800: How To Transfer an OS File to an AppServer Without FTP (4GL)
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  22/02/2002 |
|
SUMMARY:
The transfer of OS files from a client machine to an AppServer can be done with simple 4GL programs through an AppServer connection.
Thus, an application does not require reliance on FTP or on shared directories (LAN or WAN), and there is no additional deployment problem.
For performance considerations however, keep in mind that this method involves the TCP/socket layers. It should be used with caution if intensive file transfers are made.
SOLUTION:
The example below sends a file in packets of 50 kBytes and works in a stateless mode. It has been tested with a files size of up to 11 MegaBytes. The test was with NT on both sides, and also with the same byte order for the MEMPTR. With an AppServer on UNIX, it might be necessary to use the SET-BYTE-ORDER(<MemptrVar>) function to make it work as BIG-ENDIAN or LITTLE-ENDIAN.
/*ASTransfertFile.p to run persistently on an AppServer*/
DEFINE INPUT PARAMETER iFileName AS CHARACTER NO-UNDO. /*In File Name*/
DEFINE STREAM FileToSave.
DEFINE VARIABLE StreamOpened AS LOGICAL NO-UNDO.
PROCEDURE OpenStream:
OUTPUT STREAM FileToSave TO VALUE(iFileName) BINARY NO-MAP NO-CONVERT.
StreamOpened = YES.
END.
PROCEDURE CloseStream:
OUTPUT STREAM FileToSave CLOSE.
END.
PROCEDURE ReceivePacket:
DEFINE INPUT PARAMETER p AS MEMPTR NO-UNDO.
IF NOT StreamOpened THEN RUN OpenStream.
EXPORT STREAM FileToSave p.
END PROCEDURE.
/*ClientTransfertFile.p to run on the client-side */
DEFINE INPUT PARAMETER iFileName AS CHARACTER NO-UNDO. /*Path + File Name*/
DEFINE VARIABLE hAppSvr AS HANDLE NO-UNDO.
DEFINE VARIABLE hAppSvrProc AS HANDLE NO-UNDO.
DEFINE VARIABLE mthRtn AS LOGICAL NO-UNDO.
DEFINE VARIABLE MemptrPacket AS MEMPTR NO-UNDO.
DEFINE VARIABLE SentBytes AS INTEGER NO-UNDO.
DEFINE VARIABLE BytesToSend AS INTEGER NO-UNDO.
DEFINE STREAM FileToTrsf.
FILE-INFO:FILE-NAME = iFileName.
CREATE SERVER hAppSvr.
mthRtn = hAppSvr:CONNECT("-AppService cstz -H localhost -S 5163").
IF NOT mthRtn THEN RETURN ERROR "Problem to Connect to Application Server".
RUN ASTransfertFile.p PERSISTENT SET hAppSvrProc ON SERVER hAppSvr
(INPUT ENTRY(NUM-ENTRIES(iFileName,"/"),iFileName,"/")). /*to take out the path
=> the file will be saved in the working directory of the AppServer*/
INPUT STREAM FileToTrsf FROM VALUE(iFileName) BINARY NO-MAP NO-CONVERT.
REPEAT:
BytesToSend = MINIMUM(50000,FILE-INFO:FILE-SIZE - SentBytes).
IF BytesToSend = 0 THEN LEAVE.
SET-SIZE(MemptrPacket) = BytesToSend.
IMPORT STREAM FileToTrsf UNFORMATTED MemptrPacket.
RUN ReceivePacket IN hAppSvrProc (INPUT MemptrPacket).
SentBytes = SentBytes + BytesToSend.
SET-SIZE(MemptrPacket) = 0. /*Free it*/
END.
INPUT STREAM FileToTrsf CLOSE.
RUN CloseStream IN hAppSvrProc.
hAppSvr:DISCONNECT().
DELETE OBJECT hAppSvr.