631jz5350x 发表于 2016-6-8 09:44:43

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();
}
}
}
}
页: [1]
查看完整版本: java ftp 多线程