用Socket连接ftp服务器,然后嵌入到页面中,是以applet嵌入,抱错说access denies,好象是权限设置的问题,谁有ftp上传的代码共享一个,谢谢了

解决方案 »

  1.   

    在客户端上传本地文件到服务器是么?那当然要设applet的权限了
    http://qingyuan18.spaces.live.com/   这里有我以前写的关于applet权限的设置方法。
    用java写Ftp上传很简单啊,用sun的FtpClient吧:
    package com.ideal.rating;import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.text.SimpleDateFormat;
    import java.util.Date;import sun.net.TelnetInputStream;
    import sun.net.TelnetOutputStream;
    import sun.net.ftp.FtpClient;public class FTPTools { private FtpClient ftpClient ;
    private String FtpServer = "";
    private String FtpPort = "";
    private String FtpUser = "";
    private String FtpPwd = "";

    /*
     * 连接FTP服务器
     */
    public void login()
    {
    try
    {
    this.ftpClient = new FtpClient(this.FtpServer,Integer.parseInt(this.FtpPort));
                //登陆服务端FTP,设定二进制传输方式
    this.ftpClient.login(this.FtpUser,this.FtpPwd);
                //登陆服务端FTP,设定二进制传输方式
    this.ftpClient.login(this.FtpUser,this.FtpPwd);

    catch (NumberFormatException e) 
    {
    System.out.println("FTPTools:FTP连接错误!");
    e.printStackTrace();
    }
    catch (IOException e) {
    System.out.println("FTPTools:FTP连接错误!");
    e.printStackTrace();
    }
    }

    public FTPTools(String pm_sFtpServer,String pm_sFtpPort,String pm_sFtpUser,String pm_sFtpPwd)
    {
    this.FtpServer = pm_sFtpServer;
    this.FtpPort = pm_sFtpPort;
    this.FtpUser = pm_sFtpUser;
    this.FtpPwd = pm_sFtpPwd;

    }



    /*
     * @完成文件传送操作
     * @param pm_oSrcFile
     */
    public void upload(File pm_oSrcFile,String pm_sServerFilePath)
    {
    try 
    {
    //进入上传目录
    this.ftpClient.cd(pm_sServerFilePath);
    //流转换,完成上传操作
    TelnetOutputStream out = this.ftpClient.put(pm_oSrcFile.getName());
    FileInputStream ins = new FileInputStream(pm_oSrcFile);
    byte[] tmp = new byte[1024];
    int lenth = 0;
    while((lenth = ins.read(tmp))!=-1)
    {
    out.write(tmp,0,lenth);
    }
    out.flush();


    }
    catch (IOException e) {
    System.out.println("FTPTools:FTP上传错误!");
    e.printStackTrace();
    }

    }

    /*
     * @完成文件下载操作
     * @param pm_sServerFilePath 服务器文件路径
     * @param pm_sServerFileName 服务器文件名
     * @param pm_sDesPath 客户端下载文件存放路径
     */
    public void download(String pm_sServerFilePath,String pm_sServerFileName,String pm_sDesPath)
    {
    try 
    {
    //登陆服务端FTP,设定二进制传输方式
    this.ftpClient.login(this.FtpUser,this.FtpPwd);
    this.ftpClient.binary();
    //进入下载目录
    this.ftpClient.cd(pm_sServerFilePath);
    //流转换,完成下载操作
    TelnetInputStream ins = this.ftpClient.get(pm_sServerFileName);
    FileOutputStream ous = new FileOutputStream(pm_sDesPath+"\\"+pm_sServerFileName);
    byte[] tmp = new byte[1024];
    int lenth = 0;
    while((lenth = ins.read(tmp))!=-1)
    {
    ous.write(tmp,0,lenth);
    }
    ous.flush();

    }
    catch (IOException e) {
    System.out.println("FTPTools:FTP下载错误!");
    e.printStackTrace();
    }

    }
    /**
     * @param args
     */
    public static void main(String[] args) {
    // Date a = new Date();
    // Date b = new Date();
    // SimpleDateFormat c = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss");
    // System.out.println(c.format(a));
    }}