A Simple Download


In the following exercise, we will script a simple, single-file download. We will use the HTML <APPLET> tag to call JFile's DownloadClient applet from an HTML script.

The script below gets the file sample.doc from a specified directory on the server, saves it in the user's Temp directory, and displays a download confirmation page.

We will preset one file to download, using the FileNameN parameter. To add files to the download list, use "FileName2," "FileName3," etc. The user may rename a file in the download list, remove a file from the list, or remove all files from the list.
The DownloadClient Applet

Exercise: A Simple Download

  1. If you created the physical and virtual JFileScripts directories in A Simple Upload, go to Step 4. If you did not create the directories, go to Step 2.

  2. Create a directory called JFileScripts.

  3. Create a virtual directory called JFileScripts and map it to the physical JFileScripts you created in Step 2:

    1. Open the Internet Information Services (IIS) explorer.
    2. Right-click Default Web Site.
    3. Select New -> Virtual Directory.
    4. For Alias, enter JFileScripts.
    5. Browse to the JFileScripts directory you created in step 1.
    6. Check "Read" and "Run scripts."
    7. Click "Finish."

  4. Copy filetransfer.jar (for Netscape) and/or filetransfer.cab (for Internet Explorer) to the directory JFileScripts. These files are in JFile's installation directory (by default, C:\Program Files\SoftArtisans\JFile).

  5. Copy confirm.asp and sample.doc to the directory JFileScripts. You will find the files in JFile's Samples\Download\Simple directory (installed by default at C:\Program Files\SoftArtisans\JFile).

  6. Create an HTML script containing the following lines. Name the script download.htm and save it in your JFileScripts directory.
    <APPLET codebase="/JFileScripts" code="softartisans.filetransfer.DownloadClient.class" 
    height="0" width="0" mayscript archive="filetransfer.jar" name="filedownload">
    	
    	<!-- The Cabbase parameter specifies the cab file containing the download applet. -->
    	<PARAM name="cabbase" value="filetransfer.cab">
    
    	<!-- The FinalURL parameter specifies the URL to display when the download is complete. -->
    	<PARAM name="FinalURL" value="http://localhost/jfilescripts/confirm.asp">
    	
    	<!-- The FileName# parameter specifies the local path to which to download the file, and the 
    	downloaded file's name on the local machine.  When downloading more than one file, use 
    	"FileName1," "FileName2," etc. -->
    	<PARAM name="FileName1" value="c:\temp\sample.doc">
    	
    	<!-- The URL# parameter specifies the URL of the file to download from the server. 
    	When downloading more than one file, use "URL1," "URL2," etc.-->
    	<PARAM name="URL1" value="http://localhost/jfilescripts/sample.doc">
    		
    </APPLET>
  7. To run the script, open the browser, and enter the URL http://localhost/jfilescripts/download.htm. Click "Download."

Understanding the Script


To prevent the user from renaming a file on the download list, set the parameter NoRename to 1:
<PARAM name="NoRename" value="1">

To prevent the user from removing files from the download list, set the parameter NoRemove to 1:
<PARAM name="NoRemove" value="1">


Copyright © 2000-2003 SoftArtisans, Inc. All rights reserved.