java.net.*
只有更底层的socket类。

解决方案 »

  1.   

    用java.net.* 里面都有,
    一个用ftp上传文件的例子 /*
     * Created on 2005-3-30
     *
     * TODO To change the template for this generated file go to
     * Window - Preferences - Java - Code Style - Code Templates
     *//**
     * @author nizheng
     *
     * TODO To change the template for this generated type comment go to
     * Window - Preferences - Java - Code Style - Code Templates
     */
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.OutputStream;import sun.net.ftp.FtpClient;
    public class ftp {  public ftp() {
      }  private static FtpClient m_client;  protected static void disconnect()
      {
        if (m_client != null)
        {
          try
          {
            m_client.closeServer();
          }
          catch (IOException ex)
          {
          }      m_client = null;
        }
      }  protected static boolean connect(String sHost, String user,
                String password ,String sDir)
      {
        try
        {
          m_client = new FtpClient(sHost);
          m_client.login(user, password);
          m_client.cd(sDir);
          m_client.binary();
        }
        catch (Exception ex)
        {
          return false;
        }    return true;
      }  protected static boolean putFiletoServer(String m_sLocalFile,String m_sHostFile)
      {
        if (m_sLocalFile.length()==0)
        {
          return false;
        }    byte[] buffer = new byte[10240];    try
        {
          File f = new File(m_sLocalFile);
          int size = (int)f.length();
          FileInputStream in = new FileInputStream(m_sLocalFile);
          OutputStream out = m_client.put(m_sHostFile);      int counter = 0;
          while(true)
          {
            int bytes = in.read(buffer);
            if (bytes < 0)
              break;
            out.write(buffer, 0, bytes);
            counter += bytes;
          }      out.close();
          in.close();
        }
        catch (Exception ex)
        {
          return false;
        }    return true;
      }
      public static boolean putFile(String pathname,String ftpServer, String ftpUser,
                               String ftpPasswd, String ftpPath)
      {
        if (!connect(ftpServer,ftpUser,ftpPasswd,ftpPath))
        {
          return false;
        }    int pos = pathname.lastIndexOf("/");
        int len = pathname.length();    String filename = pathname.substring(pos+1,len);    if (!putFiletoServer(pathname,filename))
        {
          return false;
        }    disconnect();
        return true;
      }  /*   sample   */
      
      public static void main(String[] args)
      {
        boolean b = putFile("file.txt","172.16.3.28","Anonymous","","watool/ldmacs/share/rootdir/system/invoice/upload/");
        System.out.println(b);
      }
      
    }
      

  2.   

    我一般用jspSmartUpload包(下载很多,搜一下就有)
    下面这个是它的教程
    http://www.tongyi.net/article/20031015/200310153755_1.shtml
    如果你想自己编写,这里有它的源代码你可以参考一下:
    http://www.9soho.com/Software/Catalog64/1408.html
      

  3.   

    http://www.tongyi.net/article/20031015/200310153755_1.shtml
    http://www.9soho.com/Software/Catalog64/1408.html
    smartupload
      

  4.   

    我是用swing开发的图形界面,不是用的b/s结构,请问c/s结构下能使用smartupload吗?
      

  5.   

    to : topil(认认真真学习,塌塌实实工作)你程序中用到的 ort sun.net.ftp.FtpClient;  是哪里的类包阿?哪里能找到他的说明文档?
    我想实现的是从服务器上下载一个文件,你的例子是上传阿。
    谢谢!
      

  6.   

    简单啊,用cd命令到目录,再用PUT命令得文件啊
      

  7.   

    FtpClient ftpClient=new FtpClient();
       System.out.println("1");
       ftpClient.openServer(server);
       System.out.println("2");
       ftpClient.login(user, password);
       System.out.println("3");为什么我在登陆ftpClient.login(user, password);这个地方过不去阿?总是返回一个false。登陆名和密码没问题!请问是什么原因?
      

  8.   

    连接到的服务器还要开ftp服务吗?我的服务器用的是solaris .请问在solaris上有什么需要注意的地方?主要是路径问题。
      

  9.   

    sun.net.ftp.FtpClient是jdk里面自带的,直接去jdk的文档里面就可以找到。
    服务器当然要开FTP了才能够连接的嘛,楼主先试试你从IE里面输入你的用户名,密码能否连接上去,你那个返回false,肯定是没有连接上服务器。关于server的OS没有太大区别的
      

  10.   

    请问连接到ftp服务器后是不是直接连接到ftp指定的文件夹?如果我想下载excel文件夹下的Template.xls文件,是否这样?
     ftpClient.cd("excel/");
     ftpClient.binary();
     TelnetInputStream is=ftpClient.get("Template.xls");