sun.net.*,在jdk/lib中是不带的,好像在jre中有。在jre/lib/jsse.jar中包含了这个包。

解决方案 »

  1.   

    把你的代码帖出来,要不怎么知道你错在哪里,Ftp端口问题
      

  2.   

    我用类FtpClientEnd将FtpClient封装起来了:
    import java.io.*;
    import sun.net.ftp.*;
    import sun.net.*;public class FtpClientEnd
    {
      FtpClient aFtpClient=null;
      private String hostName=null;
      private String userName=null;
      private String userPass=null;
      private String remoteFilePath=null;
      private String localFilePath=null;
      
      private int try_time=3;
      
      public FtpClientEnd(String hostName,String userName,String userPass,String remoteFilePath,String localFilePath)
      {
        this.hostName=hostName;
        this.userName=userName;
        this.userPass=userPass;
        this.remoteFilePath=remoteFilePath;
        this.localFilePath=localFilePath;
      }
      
      public boolean connectServer()
      {
        if(hostName==null || hostName.equals(""))
        {
          System.out.println("ftp hostname can't be blank.");
          return false;
        }
        System.out.println("Connecting to host: "+hostName+"...");
        try
        {
          aFtpClient=new FtpClient(hostName);
          aFtpClient.login(userName,userPass);
          aFtpClient.binary();
        }
        catch(FtpLoginException e)
        {
          //System.out.println("无权限访问ftp主机.");
          System.out.println("not privilidged to access ftp host.");
          return false;
        }
        catch(IOException e)
        {
          //System.out.println("连接ftp主机失败.");
          System.out.println("fail to connect to ftp host.");
          return false;
        }
        catch(SecurityException e)
        {
          //System.out.println("无权限连接ftp主机.");
    System.out.println("not privilidged to connect to ftp host.");
          return false;
        }
        //System.out.println("ftp主机连接成功.");
    System.out.println("successful to connect to ftp host.");
        return true;
      }  public boolean upLoadFile(String fileName)
      {
         boolean connected=connectServer();
         int i=try_time;
         while(i>0)
         {
           if(connected==false)
             i--;
           else
             break;
         }
         if(i<=0)
           return false;     RandomAccessFile sendFile=null;
         TelnetOutputStream out=null;
         DataOutputStream output=null;
         int byteData;
         
         try
         {
           sendFile = new RandomAccessFile(localFilePath+fileName,"r");
         }
         catch(IOException e)
         {
           //System.out.println("ftp读本地文件错误。");
    System.out.println("ftp read local file error.");
           closeCon();
           return false;
         }        
         try
         {
           aFtpClient.cd(remoteFilePath);
         }
         catch(IOException e)
         {
    //System.out.println("远程路径错误。");
           System.out.println("ftp remote path error.");
           e.printStackTrace();
           closeCon();
           return false;
         }
         try
         {
           //System.out.println("正在发送文件:"+fileName+"...");
           System.out.println("Sending file: "+fileName+"...");
           sendFile.seek(0);
    System.out.println("a");
           out=aFtpClient.put(fileName);
    System.out.println("b");
           output=new DataOutputStream(out);
    System.out.println("c");
           while(sendFile.getFilePointer?-焔?G^F3/?鞛V'8{?"奁WH?4嬊?油?
      

  3.   

    是不是端口号没设??我是说你的ftp不是默认端口号
    试一试
    FtpClient(String string, int int1)再就是,我推荐给你一个包,比较省事的com.oroinc.net.ftp
      

  4.   

    com.oroinc.net.ftp这个包哪儿有?
      

  5.   

    http://www.savarese.org/oro/downloads/index.html