Advertisement
Guest User

Untitled

a guest
Aug 5th, 2015
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package ru.kamalist;
  6. import java.io.Console;
  7. import java.io.FileOutputStream;
  8. import java.io.IOException;
  9. import java.util.Date;
  10. import java.util.LinkedList;
  11. import java.util.zip.ZipOutputStream;
  12. import org.apache.commons.net.ftp.FTPClient;
  13. import org.apache.commons.net.ftp.FTPFile;
  14. import java.text.SimpleDateFormat;
  15. /**
  16. *
  17. * @author user
  18. */
  19. public class Backup {
  20.  
  21. /**
  22. * @param args the command line arguments
  23. */
  24. public static void main(String[] args) throws Exception{
  25. Console cons = System.console();
  26. String server = cons.readLine("Enter server:");
  27. String user = cons.readLine("Enter user:");
  28. char[] pass = cons.readPassword("Enter password:");
  29. FTPClient ftpc = new FTPClient();
  30. ftpc.connect(server);
  31. ftpc.login(user, new String(pass));
  32. java.util.Arrays.fill(pass,'*');
  33. String directory = cons.readLine("Enter directory:");
  34. LinkedList<String> list = new LinkedList();
  35. makeFileList(list,ftpc,directory);
  36. Worker.queue = list;
  37. SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyHHmmz");
  38. ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(server+sdf.format(new Date())+".zip" ));
  39. Worker w1 = new Worker(ftpc,zos);
  40. Worker w2 = new Worker(ftpc,zos);
  41. Thread t1 = new Thread(w1);
  42. t1.start();
  43. Thread t2 = new Thread(w2);
  44. t2.start();
  45. t1.join();
  46. t2.join();
  47. ftpc.disconnect();
  48. zos.close();
  49. }
  50.  
  51. private static void makeFileList(LinkedList<String> list, FTPClient ftpc,String dir) throws IOException{
  52. FTPFile[] files = ftpc.listFiles(dir);
  53. System.out.println(files.length);
  54. for(FTPFile file:files){
  55. String filename = file.getName();
  56. if(filename.equals(".") || filename.equals("..")) continue;
  57. if(file.isDirectory()){
  58. makeFileList(list,ftpc,dir+"/"+filename);
  59. }
  60. else if(file.isFile()){
  61. list.offer(dir+"/"+filename);
  62. }
  63.  
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement