FtpClient ftpClient=new FtpClient();
String server=jTextField1.getText();//输入的FTP服务器的IP地址
String user=jTextField2.getText();;    //登录FTP服务器的用户名
String password=jPasswordField1.getText();;//登录FTP服务器的用户名的口令
try
{
ftpClient.openServer(server);//连接FTP服务器
    ftpClient.login(user, password);//登录FTP服务器
    ftpClient.cd("数据库");          
    TelnetInputStream ti=ftpClient.list();
    int i;
      while ((i=ti.read())!=-1){
      System.out.print((char)i);}
                        
    is.close();
 } catch (Exception ex) {}

解决方案 »

  1.   

    用String怎么处理?
    http://jakarta.apache.org/commons/net/api/org/apache/commons/net/ftp/FTPClient.html
    上看帮助文档,看到一个这个方法: 
    String[] listNames() 
              Obtain a list of filenames in the current working directory This information is obtained through the NLST command.
    本来想用的,但是在编译时说找不到 listNames()这个方法。
      

  2.   

    login后加下面代码:ftpClient.setControlEncoding("GBK");
      

  3.   

    要设置编码方式,有些FTP服务器也可以手工配置编码方式,例如ServU,这时,最好将FTP服务器的编码方式与程序的编码方式统一一下。
      

  4.   


    try {
    ftpClient.openServer(server);// 连接FTP服务器
    ftpClient.login(user, password);// 登录FTP服务器
    ftpClient.cd("/home/cacao/log");
    TelnetInputStream ti = ftpClient.list();
    InputStreamReader isr = new InputStreamReader(ti, "GB2312");
    char[] buf = new char[1024];
    int len = 0;
    len = isr.read(buf);
    while (len > 0) {
    for (int i = 0;i<len;i++)
    System.out.print(buf[i]);
    len = isr.read(buf);
    } ti.close();
    } catch (Exception ex) {
    }