*****************************************
      * Program name: down.cbl
      * This web-based program demonstrates how 
      * to download a file by sending the appropriate
      * MIME header to the client's browser and 
      * using either the DISPLAYFILE or 
      * DISPLAYASCIIFILE statements, depending
      * on the type of the file to be transmitted.  The
      * method used below protects the URL (location)
      * of the file from the client, preventing
      * unauthorized, direct downloads.
      *
      * Copyright 2000 Deskware, Inc.
      *****************************************
       1 content_length  PIC 9(05).
       1 xfer_filename   PIC X(20).
       1 xfer_method     PIC X(20) VALUE `octet-stream`.
       1 xfer_filesize   PIC Z(9).


       1 web_page_html.
         5 `Content-type: text/html`.
         5 ` `.
         5 ``.
         5 `
CobolScript Download Sample Application
`. 5 `
`. 5 `

`. 5 `Select a file to download:

`. 5 `

`. 5 ``. 5 ``. 5 `
`. 5 ``. * main. GETENV USING `CONTENT_LENGTH` content_length. IF content_length > 0 ACCEPT DATA FROM WEBPAGE PERFORM send_mime_file ELSE DISPLAYLF web_page_html END-IF. GOBACK. send_mime_file. 1 binary_download PIC 9 VALUE 0. IF xfer_filename(1:8) = `down.cbl` MOVE 3019 TO xfer_filesize ELSIF xfer_filename(1:7) = `uts.cbl` MOVE 16212 TO xfer_filesize ELSIF xfer_filename(1:7) = `prb.cbl` MOVE 3120 TO xfer_filesize ELSIF xfer_filename(1:8) = `vprb.cbl` MOVE 8636 TO xfer_filesize ELSIF xfer_filename(1:9) = `input.cbl` MOVE 4668 TO xfer_filesize ELSIF xfer_filename(1:8) = `down.zip` MOVE 65282 TO xfer_filesize MOVE 1 TO binary_download END-IF. DISPLAY `Content-type: application/` & xfer_method. DISPLAY `Content-Disposition: inline; filename=` & xfer_filename. DISPLAY `Content-Description: ` & xfer_filename. DISPLAY `Content-Length: ` & xfer_filesize. DISPLAYLF. IF NOT binary_download DISPLAYASCIIFILE xfer_filename ELSE DISPLAYFILE xfer_filename END-IF.