服务器是unix环境,怎么能浏览服务器目录?
以下是我写的代码,请帮忙看看。另请指教jsp写法public class Ftpload {
    FtpClient ftpClient;
    public Ftpload() {
    }    public void connectServer(){
        //server:FTP服务器的IP地址;username:登录FTP服务器的用户名
        //password:登录FTP服务器的用户名的口令;path:FTP服务器上的路径
        ResourceBundle rb = ResourceBundle.getBundle("FtpUnload");
        String server = rb.getString("IP");
        int port = Integer.parseInt(rb.getString("Port"));
        String username = rb.getString( "Username" );
        String password = rb.getString( "Password" );        try{
            ftpClient=new FtpClient(server,port);            ftpClient.login(username, password);
            System.out.println("login success!");            ftpClient.ascii();
        }catch (IOException ex){
            ex.printStackTrace();
        }
    }    public void closeConnect(){
        try{
            ftpClient.closeServer();
        }catch (IOException ex){
            ex.printStackTrace();
        }
    }    public void upload(String resfile, String objfile)
    {        try {
            TelnetOutputStream os=ftpClient.put(objfile);
            File file_in=new File(resfile);
            FileInputStream is=new FileInputStream(file_in);
            byte[] bytes=new byte[1024];
            int c;
            while ((c=is.read(bytes))!=-1){
                os.write(bytes,0,c);
            }
            is.close();
            os.close();
        }catch (IOException ex){
            ex.printStackTrace();
        }
    }    public void load(String resfile, String objfile)
    {
        int ch;        try {
            RandomAccessFile rFile = new RandomAccessFile(objfile,"rw");
            rFile.seek(0);
            TelnetInputStream tInput=ftpClient.get(resfile);
            DataInputStream dInput = new DataInputStream(tInput);            while ( (ch = dInput.read()) >= 0) {
                rFile.write(ch);
            }
            dInput.close();
            rFile.close();        }catch (IOException ex){
            ex.printStackTrace();
        }
    }
}

解决方案 »

  1.   

    有个fileLists方法的,查查api吧
      

  2.   

    我写的这个类不能满足将客户端的文件传到服务器,也不能把服务器的文件下载到客户端
    我到底哪写错了?下面是我写的jsp
    请帮忙啊各位大大<%@ page contentType="text/html; charset=GBK" %>
    <%@ page import="com.adtec.moia.web.ftp.*"%>
    <html><body>
    <%
      FtpUnload ftp = new FtpUnload();
      String infile = "/home/test/tmp/t.txt";
      String outfile = "C:/tt.txt";
      try{ 
          ftp.connectServer();
          ftp.load(infile,outfile );
      }catch(Exception e){ 
          out.println(e.getMessage());
      }finally{
          ftp.closeConnect();
      }  out.println("<Script>window.location.href=\"ftpsucc.jsp\";</Script>");
    %>
    </body>
    </html><%@ page contentType="text/html; charset=GBK" %>
    <%@ page import="com.adtec.moia.web.ftp.*"%>
    <html><body>
    <%
      FtpUnload ftp = new FtpUnload();
      String resfile = request.getParameter("infile");
      resfile = new String(resfile.getBytes("8859_1"), "GB2312");
      String objfile = "/home/test/tmp/t.txt";      try{ 
              ftp.connectServer();
              ftp.upload(resfile,objfile);
          }catch(Exception e){ 
              out.println(e.getMessage());
          }finally{
              ftp.closeConnect();
          }%>
    </body>
    </html>
      

  3.   

    好像现在开源的smartupload用的很多,既然别人已经写好的,为什么不拿来改造一下呢?
      

  4.   

    我这倒是以前写过一个上传到ftp,从ftp下载的的源代码,是根据smartupload改的,用的apache的ftp包。如果需要,留下你的邮箱,我给你发过去