1、sun.net.ftp.*;
   这是一个不被官方支持的,但是放在JDK下面的FTP包。正因为不被支
持,所以没有官方提供API,这是其最大的缺陷之一。最重要由于不是官方支持的,
所以文档也是没有的
    [url]http://swig.stanford.edu/pub/java/javadoc/overview-summary.html[/url]
    这里有该包的API。

先给一个简单的例子:(例子来源互联网)
1)显示FTP服务器上的文件
void ftpList_actionPerformed(ActionEvent e) {
String server=serverEdit.getText();//输入的FTP服务器的IP地址
   String user=userEdit.getText();    file://登/录FTP服务器的用户名
   String password=passwordEdit.getText();//登录FTP服务器的用户名的口令
   String path=pathEdit.getText();//FTP服务器上的路径
   try {
   FtpClient ftpClient=new FtpClient();//创建FtpClient对象
   ftpClient.openServer(server);//连接FTP服务器
   ftpClient.login(user, password);//登录FTP服务器
      if (path.length()!=0) ftpClient.cd(path);
   TelnetInputStream is=ftpClient.list();
   int c;
   while ((c=is.read())!=-1) {
 System.out.print((char) c);}
               is.close();
               ftpClient.closeServer();//退出FTP服务器
        } catch (IOException ex) {;}
 }
2)从FTP服务器上下传一个文件
void getButton_actionPerformed(ActionEvent e) {
String server=serverEdit.getText();
   String user=userEdit.getText();
   String password=passwordEdit.getText();
   String path=pathEdit.getText();
   String filename=filenameEdit.getText();
  try {
   FtpClient ftpClient=new FtpClient();
   ftpClient.openServer(server);
   ftpClient.login(user, password);
      if (path.length()!=0) ftpClient.cd(path);
   ftpClient.binary();
   TelnetInputStream is=ftpClient.get(filename);
   File file_out=new File(filename);
      FileOutputStream os=new
      FileOutputStream(file_out);
      byte[] bytes=new byte[1024];
   int c;
   while ((c=is.read(bytes))!=-1) {
      os.write(bytes,0,c);
   }
      is.close();
      os.close();
      ftpClient.closeServer();
   } catch (IOException ex) {;}
 }

3)向FTP服务器上上传一个文件
void putButton_actionPerformed(ActionEvent e) {
String server=serverEdit.getText();
   String user=userEdit.getText();
   String password=passwordEdit.getText();
   String path=pathEdit.getText();
   String filename=filenameEdit.getText();
  try {
   FtpClient ftpClient=new FtpClient();
   ftpClient.openServer(server);
   ftpClient.login(user, password);
      if (path.length()!=0) ftpClient.cd(path);
   ftpClient.binary();
   TelnetOutputStream os=ftpClient.put(filename);
   File file_in=new File(filename);
      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();
      ftpClient.closeServer();
   } catch (IOException ex) {;}
 }
}
看了这个例子,应该就能用他写东西了。
这个包缺点很多,首先就是不被支持也不被官方推荐使用

其次是这个包功能过于简单,简单到无法区分FTP服务器上的File是文件还是目录,有人说
通过返回的字符串来判断,但是据说FTP在不同系统下返回的东西不大一样,所以如果通过
判断字符串会有不好移植的问题。

自己想出了一个办法,通过FtpClient中的cd方法来判断
,代码如下:
try{
ftp.cd(file);//file为当前判断的文件
//如果过了说明file是目录
}
catch(IOException e){
//说明file是文件
}
finally{
ftp.cd("..");//返回上级目录继续判断下一文件
}
我用这种方法做过尝试,结果是只能判断正确一部分,有些目录仍会被认做文件,不知道
是我的方法有错还是别的什么原因。
如果对FTP服务没有过高的要求,使用这个包还是不错的,因为他本身就包含在JDK中,不
存在CLASSPATH的问题,不需要导入外部包,较为方便。

2、org.apache.commons.net.ftp.*;

这个包在Jakarta Commons Net library里,现在的最高版本是1.4.1,可以从以下地址
下载
[url]http://mirror.vmmatrix.net/apache/jakarta/commons/net/binaries/commons-net-1.4[/url]
.1.zip
里面包含了打包好的jar,API,及全部的class文件
[url]http://mirror.vmmatrix.net/apache/jakarta/commons/net/source/commons-net-1.4.1[/url]
-src.zip
这里包含一些例子以及全部的代码
给出一个该包的例子:
...
import org.apache.commons.net.ftp.*;
...
 public static void getDataFiles( String server,
                  String username,
                  String password,
                  String folder,
                  String destinationFolder,
                  Calendar start,
                  Calendar end )
 {
   try
   {
     // Connect and logon to FTP Server
     FTPClient ftp = new FTPClient();
     ftp.connect( server );
     ftp.login( username, password );
     System.out.println("Connected to " +
          server + ".");
     System.out.print( ftp.getReplyString());
     // List the files in the directory
     ftp.changeWorkingDirectory( folder );
     FTPFile[] files = ftp.listFiles();
     System.out.println( "Number of files in dir: " + files.length );
     DateFormat df = DateFormat.getDateInstance( DateFormat.SHORT );
     for( int i=0; i<files.length; i++ )
     {
       Date fileDate = files[ i ].getTimestamp().getTime();
       if( fileDate.compareTo( start.getTime() ) >= 0 &&
         fileDate.compareTo( end.getTime() ) <= 0 )
       {
         // Download a file from the FTP Server
         System.out.print( df.format( files[ i ].getTimestamp().getTime() ) );
         System.out.println( "\t" + files[ i ].getName() );
         File file = new File( destinationFolder +
              File.separator + files[ i ].getName() );
         FileOutputStream fos = new FileOutputStream( file );
         ftp.retrieveFile( files[ i ].getName(), fos );
         fos.close();
         file.setLastModified( fileDate.getTime() );
       }
     }
     // Logout from the FTP Server and disconnect
     ftp.logout();
     ftp.disconnect();
   }
   catch( Exception e )
   {
     e.printStackTrace();
   }
 }
同sun.net.ftp相同,都是先建立FtpClient(注意两包的大小写不同)的实例,然后通过
connect()方法连接,login()方法登陆,但是org.apache.commons.net.ftp.*明显比sun.
net.ftp功能强大很多。

org.apache.commons.net.ftp.*包将FTP中的file单独出来成为了一个新类FTPFile,还有
类FTPFileEntryParser、parse,没有仔细研究,但是从字面来看应该是转化为某种形势的
类,有待研究
同时这个commons-net-1.4.1.jar包中也提供了FTP服务器,telnet,mail等一系列类库。
org.apache.commons.net.ftp.*包的缺点在于需要设置classpath,并且需要下载jakarta
-oro-2.0.8.jar这个包才能运行(如果没有这个包,会在 ftp.listFiles()方法后抛出找不
到class异常),此包无须在代码中import,只需设置在classpath中即可。下载地址:
[url]http://mirror.vmmatrix.net/apache/jakarta/oro/source/jakarta-oro-2.0.8.zip[/url]
如果想要强大的FTP服务,那么org.apache.commons.net.ftp.*包应该是你的最好选择,而
且也是开源,免费的。

这个包的问题是:
使用Jakarta Commons Net library需要在 环境变量里面编辑classpath.
这是不方便的地方。

另外IBM也有提供一个ftp包。大家有兴趣可以搜索一下。