Zip Download


Transferring zip files can reduce network load and increase the speed of transfers. When downloading a zip file, JFile can be set to automatically extract the zipped files to a specified location on the client machine. To enable automatic zip extractions, set the parameter UnzipFiles to "1".

When UnzipFiles is enabled, a downloaded zip file will be extracted to the folder specified by the parameter FilenameN. Within this folder, if the zip file contains relative paths, JFile will create the necessary sub-directories, maintaining the original directory structure.

You can download multiple zip files to different directories by using multiple FilenameNs and URLNs.

Enabling UnzipFiles allows you to download both zip files and non-zip files.

If a file with the extension .zip is not a valid zip file, it will not be extracted or saved. When this occurs, JFile will send an error message to the Java Console, and proceed to download other specified files.

Exercise 9: Zip Download

  1. If you created the physical and virtual JFileScripts directories in a previous lesson, go to Step 4. If you did not create the directories, go to Step 2.

  2. Create a directory called JFileScripts.

  3. 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).

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

  5. Create an HTML script containing the following lines. Name the script zipdownload.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">
    	
    	<!-- Setting UnzipFiles to 1 enables the automatic exraction of a zip file after 
    	it is downloaded. -->
    	<PARAM name="UnzipFiles" value="1">
    	
    	<!-- The FileName# parameter specifies the local path to which to download and extract 
    	the zip file.  When downloading more than one file, use 
    	"FileName1," "FileName2," etc. -->
    	<PARAM name="FileName1" value="c:\temp\sample.zip">
    		
    	<!-- 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.zip">
    		
    </APPLET>
  6. To run the script, open the browser, and enter the URL http://localhost/jfilescripts/zipdownload.htm. Click "Download."

  7. You will find the extracted files sample.doc and sample2.doc in the directory c:\temp.

Understanding the Script


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