Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package ru.kamalist;
- import java.io.Console;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.util.Date;
- import java.util.LinkedList;
- import java.util.zip.ZipOutputStream;
- import org.apache.commons.net.ftp.FTPClient;
- import org.apache.commons.net.ftp.FTPFile;
- import java.text.SimpleDateFormat;
- /**
- *
- * @author user
- */
- public class Backup {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) throws Exception{
- Console cons = System.console();
- String server = cons.readLine("Enter server:");
- String user = cons.readLine("Enter user:");
- char[] pass = cons.readPassword("Enter password:");
- FTPClient ftpc = new FTPClient();
- ftpc.connect(server);
- ftpc.login(user, new String(pass));
- java.util.Arrays.fill(pass,'*');
- String directory = cons.readLine("Enter directory:");
- LinkedList<String> list = new LinkedList();
- makeFileList(list,ftpc,directory);
- Worker.queue = list;
- SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyHHmmz");
- ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(server+sdf.format(new Date())+".zip" ));
- Worker w1 = new Worker(ftpc,zos);
- Worker w2 = new Worker(ftpc,zos);
- Thread t1 = new Thread(w1);
- t1.start();
- Thread t2 = new Thread(w2);
- t2.start();
- t1.join();
- t2.join();
- ftpc.disconnect();
- zos.close();
- }
- private static void makeFileList(LinkedList<String> list, FTPClient ftpc,String dir) throws IOException{
- FTPFile[] files = ftpc.listFiles(dir);
- System.out.println(files.length);
- for(FTPFile file:files){
- String filename = file.getName();
- if(filename.equals(".") || filename.equals("..")) continue;
- if(file.isDirectory()){
- makeFileList(list,ftpc,dir+"/"+filename);
- }
- else if(file.isFile()){
- list.offer(dir+"/"+filename);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement