`
student_11
  • 浏览: 16244 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

java ftp 多线程

阅读更多
引用
这里用了参数的传递

import java.io.IOException;

public class MyThread implements Runnable{
    
    private String userName;
    private String passWord;
    private String serverIp;
    private String localPath;
    private String remotePath;
    private static int tag;
    public void upload(String userName,String passWord,String serverIp,String localPath,String remotePath){
        
        this.userName=userName;
        this.passWord=passWord;
        this.serverIp=serverIp;
        this.localPath=localPath;
        this.remotePath=remotePath;
    }
    
    public void run(){
        FtpClient ftp =new FtpClient();
        try {
            ftp.connectServer(serverIp, userName, passWord);
            ftp.uploadMoreFiles(localPath, remotePath);
            tag++;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    
}

-------------main-----

public class MainFtp {
   
    public static void main(String[] args) throws IOException{
        FtpClient ftp =new FtpClient();
        //连接服务器
//        String line=null;
        BufferedReader br= new BufferedReader(new InputStreamReader(new FileInputStream("server.conf")));
//        line =br.readLine();
        String userName="";
        String passWord = "";
        String localPath="E:/ftpclient";
        String remotePath = "/home/guest";
       
        MyThread server11 = new MyThread();
        MyThread server12 = new MyThread();

        server11.upload(userName, passWord, br.readLine(), localPath, remotePath);
        server12.upload(userName, passWord, br.readLine(), localPath, remotePath);
       
       Thread tserver11= new Thread(server11);
        Thread tserver12= new Thread(server12);
       
       tserver11.start();
        tserver12.start();
       
       boolean fin = flase;
       while(!fin){
            if(MyThread.tag==2){
                  System.our.println("ftp over");
                  MyThread.tag=MyThread.tag+1;
                  br.close();
            }
            
       }
    }

}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics