about the sun.net.ftp.ftpclient package
843790Jul 8 2006 — edited Jul 10 2006i have created a simple applet that uses the FtpClient object, when i execute the applet the program stops at line 31 m_client = new FtpClient(host);
and produces this error in the textarea of the applet:
java.security.AccessControlException: access denied (java.lang.RuntimePermission accessClassInPackage.sun.net.ftp)
what does this mean?
can i use this code in a applet?
how can i fix this?
the reason i am using this code is that i am going to send the ftp server data from java applet to javascript......
here is the code:
import java.io.IOException;
import java.util.StringTokenizer;
import sun.net.TelnetInputStream;
import sun.net.ftp.FtpClient;
import java.net.*;
import java.awt.*;
import java.applet.*;
public class FtpGetFileSizeDemo extends Applet
{
private FtpClient m_client;
TextArea ta;
public void init()
{
ta= new TextArea("",50,50);
add(ta);
/**try
{
getAppletContext().showDocument(new URL("javascript:doAlert(\"" + "hello" +"\")"));
}
catch (MalformedURLException me) { }**/
connect("myapps.somee.com","redoc01","ullafi01","myapps.somee.com");
}
public void connect(String host, String user, String password, String sDir)
{
try
{
//System.out.println("Connecting to host " + host);
ta.append("Connecting to host " + host);
m_client = new FtpClient(host);
m_client.login(user, password);
ta.append("User " + user + " login OK");
//System.out.println("User " + user + " login OK");
//System.out.println(m_client.welcomeMsg);
ta.append(m_client.welcomeMsg);
//m_client.cd(sDir);
//System.out.println("Directory: " + sDir);
m_client.binary();
ta.append("Success.");
//System.out.println("Success.");
retreiveDirInfo(sDir);
}
catch (Exception ex)
{
ta.append("\nError: " + ex.toString());
}
}
protected void disconnect()
{
if (m_client != null)
{
try
{
m_client.closeServer();
}
catch (IOException ex)
{
}
m_client = null;
}
}
public void retreiveDirInfo(String directory)throws IOException
{
TelnetInputStream lst = m_client.list();
String str = "";
while (true)
{
int c = lst.read();
char ch = (char) c;
if (c < 0 || ch == '\n')
{
System.out.print(str);
ta.append(str+"\n");
try
{
getAppletContext().showDocument(new URL("javascript:doAlert(\"" + str +"\")"));
}
catch (MalformedURLException me) { }
str = "";
}
if(c <= 0)
break;
str += ch;
}
}
public static void main(String args[])throws IOException
{
FtpGetFileSizeDemo f = new FtpGetFileSizeDemo();
f.connect("myapps.somee.com","redoc01","ullafi01","myapps.somee.com");
}
}