McK said:
Hi all, i need to make a little applet for my website to upload file (5/8mb)
Peace be unto you.
Try
http://jvftp.sourceforge.net/
Features (copied from web site):
-Uploads / downloads files
-Recursive directory uploads
-Concurrent data transfers
-Both passive / active data transfer modes
-Swing components for browsing files and directories
-AWT components for browsing files and directories
This ftp library is licensed under the GPL
according
to the homepage (
http://jvftp.sourceforge.net/)
or LGPL according to the sourceforge
page (
http://sourceforge.net/projects/jvftp).
Here is info about the GPL
http://www.gnu.org/copyleft/gpl.html
Anyways,
This example illustrates an unsigned version
that works only on
Microsoft Internet Explorer JVM 1.1.
Enter your password first.
Enter a file name in the north box
Enter your content in the center box.
I successfully upload 855 kb of text.
On Server
jvftplib.cab
FtpApplet.class
FtpApplet$DialogFrame.class
Ftp.html
COPYING (license)
1. Downloaded jvftp-bin-0_72.zip
http://sourceforge.net/projects/jvftp
2. Renamed jvftp-AWT.jar to jvftp-AWT.zip so I can easily unzip it.
3. Created Comparable.java (package java lang)
Obtained it from
http://www.opensource.apple.com/darwinsource/10.3/gccfast-1614/libjava/java/lang/Comparable.java
This is licensed under the GPL
4. Compiled it using target since Internet Explorer has 1.1 jvm
javac -target 1.1 Comparable.java
5. Placed it in C:\downloads\jvftp-bin-0_72\jvftp\lib\jvftp-AWT\java\lang
6. Created a CAB file since Internet Explorer does not support jar
cabarc -r -p -P downloads\jvftp-bin-0_72\jvftp\lib\jvftp-AWT\ n jvftplib.cab C:\downloads\jvftp-bin-0_72\jvftp\lib\jvftp-AWT\*.*
-r stands for recursive
-p keeps the directory structure
-P strips the path from the absolute path to create a relative path
n create new cab
See reference to obtain cabarc.exe
7.Created Test Applet
<code>
import java.awt.*;
import java.applet.*;
import java.util.*;
import java.net.*;
import java.io.*;
import java.text.*;
import cz.dhl.io.*;
import cz.dhl.ftp.*;
public class FtpApplet extends Applet
{
private String username="";
private String password="";
private String host="";
TextArea textDisplay = new TextArea(80,24);
TextField fileName = new TextField(10);
public void init()
{
host = getParameter("host");
username = getParameter("username");
new DialogFrame("Enter Password");
setLayout(new BorderLayout());
add("North", fileName);
add("Center",textDisplay);
add("South", new Button("Post"));
}
public boolean action(Event e, Object arg)
{
String label = (String)arg;
if (label.equals("Clear"))
{
textDisplay.setText("");
}
else if (label.equals("Post"))
{
doPost();
}
return true;
}
public void doPost()
{
FtpOutputStream os = null;
String line;
FtpConnect cn = FtpConnect.newConnect("ftp://"+host+"/");
cn.setUserName(username);
cn.setPassWord(password);
Ftp cl = new Ftp();
try
{
cl.connect(cn);
FtpFile file = new FtpFile(fileName.getText(), cl);
System.out.println("From: " + file.toString());
boolean append = true;
os = new FtpOutputStream(file,append);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os));
line="<pre>"+textDisplay.getText()+"</pre>";
bw.write(line,0,line.length());
bw.close();
}
catch (IOException e)
{
System.out.println(e);
}
finally
{
if (os != null)
{
try
{
os.close();
}
catch (IOException e)
{
}
cl.disconnect();
}
}
textDisplay.setText("");
}
public class DialogFrame extends Frame
{
TextField inPassword = new TextField(10);
DialogFrame(String title)
{
super(title);
inPassword.setEchoChar('*');
setLayout(new FlowLayout());
add(inPassword);
add(new Button("OK"));
pack();
show();
}
public boolean action(Event e, Object arg)
{
String label = (String)arg;
if (label.equals("OK"))
{
password=inPassword.getText();
dispose();
}
return true;
}
}
}
</code>
8. Compile using target since 1.1 jvm
javac -classpath "C:\downloads\jvftp-bin-0_72\jvftp\lib\jvftp-AWT.jar" -target 1.1 FtpApplet.java
10. Created the Ftp.html page which uses Cabbase so it downloads everytime.
A better solution is Useslibrary (see references),
which allows a archive to be download once and
persist.
<html>
<head>
</head>
<body topmargin=0 leftmargin=0>
<applet code=FtpApplet.class width=320 height=240
archive="jvftplib.jar" codebase=".">
<param name="cabbase" value="jvftplib.cab">
<param name="username" value="mromarkhan">
<param name="host" value="members.rogers.com">
</applet>
</body>
</html>
-- References
HOW TO: Create a Cab file for java
Packaging ActiveX Controls
http://msdn.microsoft.com/library/default.asp?url=/workshop/components/activex/packaging.asp
HOW TO: Downloading cabarc.exe
Need to download Cabarc which is in the Platform SDK bin directory
or
Microsoft Knowledge Base Article - 310618
http://support.microsoft.com/default.aspx?scid=kb;en-us;310618
HOW TO: Permanently persist java archives for faster loading
"The important feature to note regarding Useslibrary is that it will install the package on the user's machine permanently until they are removed by the user, whereas the Cabbase parameter will simply download and use the CAB every time the user hits the
179652 - HOWTO: Deploy Java in Internet Explorer 4.0 and Netscape 4.0:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;179652
HOW TO: Using jar files in Internet Explorer
You can't, you need to use cab
So instead of archive you use a param which Internet Explorer recognizes
179652 - HOWTO: Deploy Java in Internet Explorer 4.0 and Netscape 4.0:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;179652
HOW TO: Using FTP with Java 1.1
Java FTP Client Library:
http://jvftp.sourceforge.net/
HOW TO: Laying out components along the borders in Java 1.1
add("NORTH", component);
Trail: Creating a User Interface (AWT Only)
http://java.sun.com/docs/books/tutorial/ui/index.html
HOW TO: Including multiple jar files in an applet.
"archive = uri-list [CT]
This attribute specifies a comma-separated list of
URIs for archives containing classes and
other resources that will be 'preloaded'."
13 Objects, Images, and Applets
http://www.w3.org/TR/REC-html40/struct/objects.html#h-13.4
HOW TO: Compiling applets on Internet Explorer
HOW TO: Resolving Class Not Defined errors with Applets in Internet Explorer
javac -target 1.1 MyApplet.class
http://java.sun.com/j2se/1.3/docs/tooldocs/win32/javac.html
Have a good day.