Advertisement
Guest User

Untitled

a guest
Dec 21st, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 28.68 KB | None | 0 0
  1. package sample;
  2.  
  3. import java.awt.event.ActionListener;
  4. import java.io.*;
  5. import java.lang.reflect.Field;
  6. import java.net.*;
  7. import java.nio.charset.Charset;
  8. import java.nio.charset.StandardCharsets;
  9. import java.nio.file.Files;
  10. import java.nio.file.Path;
  11. import java.nio.file.Paths;
  12. import java.sql.Connection;
  13. import java.sql.ResultSet;
  14. import java.sql.SQLException;
  15. import java.text.DateFormat;
  16. import java.text.SimpleDateFormat;
  17. import java.util.ResourceBundle;
  18.  
  19. import com.chilkatsoft.CkFtp2;
  20. import javafx.application.Application;
  21. import javafx.application.Platform;
  22. import javafx.beans.property.SimpleStringProperty;
  23. import javafx.beans.value.ChangeListener;
  24. import javafx.beans.value.ObservableValue;
  25. import javafx.collections.FXCollections;
  26. import javafx.collections.ObservableList;
  27. import javafx.event.EventHandler;
  28. import javafx.fxml.FXML;
  29. import javafx.fxml.FXMLLoader;
  30. import javafx.fxml.Initializable;
  31. import javafx.geometry.Pos;
  32. import javafx.scene.Node;
  33. import javafx.scene.Parent;
  34. import javafx.scene.Scene;
  35. import javafx.scene.control.*;
  36. import javafx.scene.control.TableColumn.CellDataFeatures;
  37. import javafx.scene.image.Image;
  38. import javafx.scene.image.ImageView;
  39. import javafx.scene.input.MouseEvent;
  40. import javafx.scene.layout.StackPane;
  41. import javafx.scene.paint.Color;
  42. import javafx.stage.Stage;
  43. import javafx.util.Callback;
  44. import javafx.fxml.Initializable;
  45. import javafx.scene.input.MouseEvent;
  46. import javafx.stage.FileChooser;
  47. import javax.annotation.Resource;
  48. import javax.lang.model.type.ErrorType;
  49. import javax.naming.NamingException;
  50. //import javax.management.Notification;
  51.  
  52. import javafx.event.ActionEvent;
  53. import javafx.scene.control.Alert.AlertType;
  54. import API.easyFTP;
  55.  
  56. import javafx.util.Duration;
  57. import org.apache.commons.io.FileUtils;
  58. import org.controlsfx.control.Notifications;
  59. import org.omg.CORBA.INTERNAL;
  60. import org.slf4j.Logger;
  61. import org.slf4j.LoggerFactory;
  62. //I know this isn't needed, but I thought I will just do it ;/
  63.  
  64. import org.apache.commons.net.ftp.FTPFile;
  65. import org.apache.commons.net.ftp.FTPReply;
  66.  
  67. import java.io.File;
  68.  
  69. import static java.lang.System.out;
  70. import static java.lang.System.*;
  71. //import static sample.ConnectionController.ChangeSource.EXTERNAL;
  72. //import com.adeel.library.easyFTP;
  73. import API.AbstractFTPClient;
  74. import API.FTPFileInfoVO;
  75. import API.FTPLogCommandListener;
  76. import API.FTPTransferMode;
  77. import API.ServerToClient;
  78. import API.ServerToServer;
  79.  
  80. import java.util.concurrent.TimeUnit;
  81. import java.util.logging.Handler;
  82. import java.util.regex.Matcher;
  83. import java.util.regex.Pattern;
  84.  
  85. import javafx.event.ActionEvent;
  86. import javafx.scene.control.Alert;
  87. import org.apache.commons.net.ftp.FTPClient;
  88. import org.apache.commons.net.ftp.FTPReply;
  89. import org.slf4j.Logger;
  90. import org.slf4j.LoggerFactory;
  91. import sample.EzyFTP;
  92. import java.util.*;
  93. import org.controlsfx.*;
  94. import javafx.application.Application;
  95. import javafx.event.ActionEvent;
  96. import javafx.event.EventHandler;
  97. import javafx.scene.Scene;
  98. import javafx.scene.control.Alert;
  99. import javafx.scene.control.Alert.AlertType;
  100. import javafx.scene.control.Button;
  101. import javafx.scene.control.TreeItem;
  102. import javafx.scene.control.TreeView;
  103. import javafx.scene.layout.BorderPane;
  104. import javafx.stage.DirectoryChooser;
  105. import javafx.stage.Stage;
  106. import org.fxmisc.livedirs.*;
  107. import com.chilkatsoft.CkZip;
  108. import java.util.concurrent.TimeUnit;
  109. import java.util.stream.Stream;
  110. import org.fxmisc.livedirs.*;
  111.  
  112. import API.*;
  113. import sun.plugin2.main.client.DisconnectedExecutionContext;
  114.  
  115. /**
  116.  *
  117.  * @author The4kGamer
  118.  */
  119. public class ConnectionController {
  120.  
  121.  
  122.     @FXML
  123.     private TextField TxtUsername;
  124.  
  125.  
  126.  
  127.     @FXML
  128.     private TextField TxtHost;
  129.  
  130.     @FXML
  131.     private PasswordField TxtPassword;
  132.  
  133.  
  134.     @FXML
  135.     private TextField Port;
  136.  
  137.  
  138.     @FXML
  139.     private CheckBox CheckBoxSSLonly;
  140.  
  141.  
  142.  
  143.     @FXML
  144.     private Label Label;
  145.  
  146.     @FXML
  147.     private Button ConnectBtn;
  148.  
  149.  
  150.  
  151.     @FXML
  152.  
  153.     private TextArea Console;
  154.  
  155.  
  156.     @FXML
  157.  
  158.     private Button ConsoleTest;
  159.  
  160.     @FXML
  161.  
  162.  
  163.     private MenuButton MethodOfTransfer; //kk i am retarted.....
  164.  
  165.  
  166.     @FXML
  167.     private Button LocalDirBtn;
  168.  
  169.     @FXML
  170.     private Node root;
  171.  
  172.  
  173.     @FXML
  174.  
  175.     private Button DisconnectButton;
  176.  
  177.  
  178.     @FXML
  179.  
  180.     private Label UsernameLabel;
  181.  
  182.     @FXML
  183.  
  184.     private Label PasswordLabel;
  185.  
  186.     @FXML
  187.  
  188.     private CheckBox SaveInfoCheckBtn;
  189.  
  190.     @FXML
  191.  
  192.     private MenuButton SavedMenu;
  193.  
  194.  
  195.     @FXML
  196.  
  197.     private Button TreeView;
  198.  
  199.  
  200.     // define menu items
  201.     MenuItem menuItem1 = new MenuItem("Transfer from server to local directory");
  202.     MenuItem menuItem2 = new MenuItem("Transfer from local directory to server");
  203.     MenuItem menuItem3 = new MenuItem("Transfer from server to server??!?!?");
  204.  
  205.  
  206.  
  207.  
  208.     public void FetchSavedConnections() throws IOException {
  209.  
  210.  
  211.  
  212.  
  213.     }
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.     //demonstreigtion of current client functionality...
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.     public int AttemptedReconnect = 1;
  229.  
  230.  
  231.  
  232.  
  233.     enum ChangeSource {
  234.         INTERNAL,
  235.         EXTERNAL,
  236.     }
  237.  
  238.  
  239.     public void TestFXDir () {
  240.     }
  241.  
  242.  
  243.  
  244.  
  245.     public void ChooseDirectory(ActionEvent event) {
  246.  
  247.         FileChooser fc = new FileChooser();
  248.         File selectedFile = fc.showOpenDialog(null);
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.     }
  259.  
  260.  
  261.     //ill be adding GUI features such as drop and drag files in, I already have a directory tree view lib located.
  262.     //when method 'servertoserver' transfer is selected
  263.     public void ServerToServerTransfer(ActionEvent event) {
  264.  
  265.     }
  266.  
  267.     //define DLL lib path
  268.  
  269.     public static void setDllLibraryPath(String resourceStr) {
  270.         try {
  271.             System.setProperty("java.library.path", resourceStr);
  272.  
  273.             Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
  274.             fieldSysPath.setAccessible(true);
  275.             fieldSysPath.set(null, null);
  276.         } catch (Exception ex) {
  277.             ex.printStackTrace();
  278.             throw new RuntimeException(ex);
  279.         }
  280.     }
  281.  
  282.  
  283.     public int UniqueConnectionCount;
  284.  
  285.  
  286.     public void TestConsole() {
  287.  
  288.  
  289.         Console.setStyle("-fx-text-inner-color: green");
  290.  
  291.  
  292.  
  293.         Console.setText(Console.getText() + "CONNECTED TO: \n");
  294.         ConsoleUpdate();
  295.  
  296.     }
  297.  
  298.     public int disconnect = 1;
  299.     public int i = 0;
  300.     //connect to FTP (now that I am going to be using chilkat)
  301.     public void TestConnect(ActionEvent event) throws Exception{
  302.         String Username = TxtUsername.getText();
  303.         String Password = TxtPassword.getText();
  304.         String IP = TxtHost.getText();
  305.         disconnect = 1;
  306.         i = 0;
  307.  
  308.  
  309.         //CheckFields();
  310.  
  311.  
  312.         setDllLibraryPath("C:\\Users\\admin\\Desktop\\DLL PATH");
  313.  
  314.  
  315.         try {
  316.             System.load("C:\\Users\\admin\\Desktop\\DLL PATH\\chilkat.dll");
  317.         } catch (UnsatisfiedLinkError e) {
  318.             System.err.println("Native code library failed to load.\n" + e);
  319.  
  320.         }
  321.  
  322.  
  323.  
  324.  
  325.  
  326.         CkFtp2 ftp = new CkFtp2();
  327.  
  328.         String ErrorType = "";
  329.         if (ftp.lastErrorText().contains("530 Login authentication failed")) {
  330.             ErrorType = " Password required for user:" + Username + " \n Login or Password was incorrect";
  331.         }
  332.         else if (ftp.lastErrorText().contains("Failed to get host address info. ")) {
  333.             ErrorType = " Hostname specified does not exist, please insure that the server is up before connecting \n ";
  334.  
  335.         }
  336.  
  337.  
  338.  
  339.  
  340.         boolean success;
  341.  
  342.  
  343.  
  344.  
  345.  
  346.         boolean isSelected = CheckBoxSSLonly.isSelected();
  347.  
  348.         boolean SaveShizz = SaveInfoCheckBtn.isSelected();
  349.  
  350.  
  351.         if(isSelected == true){
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359.             ftp.put_Ssl(true);
  360.  
  361.  
  362.  
  363.  
  364.  
  365.         }
  366.  
  367.         ftp.put_Hostname(IP);
  368.         ftp.put_Username(Username);
  369.         ftp.put_Password(Password);
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.         success = ftp.Connect();
  377.         if (success == true) {
  378.             Date date = new Date();
  379.             String strDateFormat = "hh:mm:ss a";
  380.             DateFormat dateFormat = new SimpleDateFormat(strDateFormat);
  381.             String formattedDate= dateFormat.format(date);
  382.             File BigFile = new File("C:\\Users\\admin\\Desktop\\EzyFTPClient\\src\\sample\\");
  383.  
  384.             BigFile = new File(IP + formattedDate + " Log");
  385.  
  386.  
  387.             if (SaveShizz == true) {
  388.  
  389.  
  390.                 File file = new File("C:\\Users\\admin\\Desktop\\EzyFTPClient\\src\\sample\\ConnectionHistory");
  391.                 if(FileUtils.readFileToString(file).contains(IP + " " + Username + " " + Password)) {
  392.                     //ill place a 'you have just entered saved credentials, next time for your ease, select your desired server's address from the "Saved Credentials" bar
  393.  
  394.  
  395.  
  396.  
  397.                 } else
  398.                 {
  399.  
  400.  
  401.  
  402.  
  403.  
  404.                     File Sysfile = new File("C:\\Users\\admin\\Desktop\\EzyFTPClient\\src\\sample\\Sys");
  405.  
  406.                     Stream<String> lines = Files.lines(Paths.get("C:\\Users\\admin\\Desktop\\EzyFTPClient\\src\\sample\\Sys"));
  407.  
  408.                     String SavedConnectionNumber = lines.skip(7).findFirst().get();
  409.  
  410.                     //lowest numeral value of free save spot
  411.                     int SavedConnectINTEGAR = Integer.parseInt(SavedConnectionNumber);
  412.  
  413.                     int FlexableInt = Integer.parseInt(SavedConnectionNumber);
  414.  
  415.  
  416.                     FlexableInt--;
  417.                     FlexableInt--;
  418.  
  419.                     String RealInt = String.valueOf(FlexableInt);
  420.  
  421.  
  422.  
  423.                     if (FlexableInt>=0) {
  424.  
  425.                         //File HistFile = new File("C:\\Users\\admin\\Desktop\\EzyFTPClient\\src\\sample\\Sys");
  426.  
  427.                         Stream<String> HistoryLines1 = Files.lines(Paths.get("C:\\Users\\admin\\Desktop\\EzyFTPClient\\src\\sample\\Sys"));
  428.                         String GetDetails1 = lines.skip(0).findFirst().get();
  429.                         String GetDetails2 = lines.skip(1).findFirst().get();
  430.                         String GetDetails3 = lines.skip(2).findFirst().get();
  431.                         String GetDetails4 = lines.skip(3).findFirst().get();
  432.                         String GetDetails5 = lines.skip(4).findFirst().get();
  433.                         String GetDetails6 = lines.skip(5).findFirst().get();
  434.                         String GetDetails7 = lines.skip(6).findFirst().get();
  435.                         String GetDetails8 = lines.skip(7).findFirst().get();
  436.                         String GetDetails9 = lines.skip(8).findFirst().get();
  437.  
  438.  
  439.  
  440.  
  441.  
  442.                         MenuItem m1 = new MenuItem(GetDetails1);
  443.                         MenuItem m2 = new MenuItem(GetDetails2);
  444.                         MenuItem m3 = new MenuItem(GetDetails3);
  445.                         MenuItem m4 = new MenuItem(GetDetails4);
  446.                         MenuItem m5 = new MenuItem(GetDetails5);
  447.                         MenuItem m6 = new MenuItem(GetDetails6);
  448.                         MenuItem m7 = new MenuItem(GetDetails7);
  449.                         MenuItem m8 = new MenuItem(GetDetails8);
  450.                         MenuItem m9 = new MenuItem(GetDetails9);
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.                         if (GetDetails1 != "1024718237409182740927834023") {
  462.  
  463.                             SavedMenu.getItems().add(m1);
  464.  
  465.                         }
  466.                         if (GetDetails1 != "1024718237409182740927834023") {
  467.  
  468.                             SavedMenu.getItems().add(m1);
  469.  
  470.                         }
  471.                         if (GetDetails2 != "1024718237409182740927834023") {
  472.  
  473.                             SavedMenu.getItems().add(m2);
  474.  
  475.                         }
  476.                         if (GetDetails3 != "1024718237409182740927834023") {
  477.  
  478.                             SavedMenu.getItems().add(m3);
  479.  
  480.                         }
  481.                         if (GetDetails4 != "1024718237409182740927834023") {
  482.  
  483.                             SavedMenu.getItems().add(m4);
  484.  
  485.                         }
  486.                         if (GetDetails5 != "1024718237409182740927834023") {
  487.  
  488.                             SavedMenu.getItems().add(m5);
  489.  
  490.                         }
  491.                         if (GetDetails6 != "1024718237409182740927834023") {
  492.  
  493.                             SavedMenu.getItems().add(m6);
  494.  
  495.                         }
  496.                         if (GetDetails7 != "1024718237409182740927834023") {
  497.  
  498.                             SavedMenu.getItems().add(m7);
  499.  
  500.                         }
  501.                         if (GetDetails8 != "1024718237409182740927834023") {
  502.  
  503.                             SavedMenu.getItems().add(m8);
  504.  
  505.                         }
  506.                         if (GetDetails9 != "1024718237409182740927834023") {
  507.  
  508.                             SavedMenu.getItems().add(m9);
  509.  
  510.                         }
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.                     }
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.  
  537.  
  538.  
  539.  
  540.  
  541.  
  542.  
  543.                     SavedConnectINTEGAR++;
  544.  
  545.  
  546.  
  547.                     String NumberToPutInThere = String.valueOf(SavedConnectINTEGAR);
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555.  
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571.  
  572.                     String OOFT = "ooft";
  573.  
  574.                     //String SavedConnectionNumber = Files.readAllLines(Paths.get("C:\\Users\\admin\\Desktop\\EzyFTPClient\\src\\sample\\Sys")).get(8);
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.                     System.out.print("New connection details detected, OOFT");
  584.                     Path SysPath = Paths.get("C:\\Users\\admin\\Desktop\\EzyFTPClient\\src\\sample\\Sys");
  585.  
  586.                     Charset charset = StandardCharsets.UTF_8;
  587.                     String ConnectionNumeralValue = Integer.toString(UniqueConnectionCount);
  588.  
  589.  
  590.  
  591.                     String SafeConnectionNumeral = (SavedConnectionNumber + "1024718237409182740927834023");
  592.  
  593.  
  594.  
  595.  
  596.                     String SysContent = new String(Files.readAllBytes(SysPath), charset);
  597.  
  598.                     SysContent = SysContent.replaceAll(SavedConnectionNumber, NumberToPutInThere);
  599.                     Files.write(SysPath, SysContent.getBytes(charset));
  600.  
  601.  
  602.  
  603.                     Path path = Paths.get("C:\\Users\\admin\\Desktop\\EzyFTPClient\\src\\sample\\ConnectionHistory");
  604.  
  605.  
  606.                     String HistoryContent = new String(Files.readAllBytes(path), charset);
  607.  
  608.                     HistoryContent = HistoryContent.replaceAll(SafeConnectionNumeral, IP + " " + Username + " " + Password);
  609.  
  610.  
  611.                     System.out.print("New connection details detected, OOFT");
  612.  
  613.  
  614.  
  615.  
  616.                     //1024718237409182740927834023 is something I hope no one ever has as either their username, password or host address for an FTP server
  617.  
  618.                     System.out.print(SafeConnectionNumeral);
  619.  
  620.                     //find out how many saved connections there are
  621.  
  622.  
  623.  
  624.  
  625.  
  626.  
  627.  
  628.                     MenuItem m1 = new MenuItem(IP + " " + Username);
  629.  
  630.  
  631.  
  632.  
  633.  
  634.  
  635.  
  636.                     SavedMenu.getItems().add(m1);
  637.  
  638.  
  639.  
  640.  
  641.  
  642.  
  643.  
  644.  
  645.                     //String content = new String(Files.readAllBytes(path), charset);
  646.  
  647.  
  648.  
  649.  
  650.                     HistoryContent = HistoryContent.replaceAll(SafeConnectionNumeral, IP + " " + Username + " " + Password);
  651.                     Files.write(path, HistoryContent.getBytes(charset));
  652.  
  653.  
  654.                 }
  655.  
  656.             }
  657.             //add to fast connection (connection without having to re enter in all your details)
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.  
  665.  
  666.  
  667.  
  668.             i = 0;
  669.  
  670.             UsernameLabel.setText(Username);
  671.             UsernameLabel.setTextFill(Color.web("008000"));
  672.             //I know I named the host button 'passwordlabel', I am too lazy to change it back..
  673.             PasswordLabel.setText(IP);
  674.  
  675.             PasswordLabel.setTextFill(Color.web("008000"));
  676.  
  677.             Console.setText("Connection to " + IP + " Was successful :)");
  678.             Console.setStyle("-fx-text-inner-color: green");
  679.  
  680.  
  681.  
  682.             Console.setText(Console.getText() + "CONNECTED TO: \n" + IP + " ");
  683.             ConsoleUpdate();
  684.  
  685.  
  686.             TimeUnit.SECONDS.sleep(5);
  687.  
  688.             RepeteTick();
  689.  
  690.  
  691.  
  692.  
  693.  
  694.  
  695.  
  696.  
  697.  
  698.  
  699.  
  700.  
  701.  
  702.  
  703.         }
  704.         else
  705.         {
  706.  
  707.  
  708.             Console.setText(Console.getText() + ErrorType + "\n");
  709.             System.out.print(ErrorType);
  710.             System.out.print(ftp.lastErrorText());
  711.  
  712.             System.out.print(ErrorType);
  713.             String CHUGONTHATMILKBOY="FALSE";
  714.             System.out.println("Exception");
  715.  
  716.             if (TxtHost.getText().equals("")) {
  717.                 Label.setText("CONNECTION TO (>)(>)NULL(<)(<) Failed!");
  718.                 CHUGONTHATMILKBOY="TRUE";
  719.  
  720.             }
  721.             else
  722.             {
  723.                 Label.setText("CONNECTION TO  " + IP + "  Failed!");
  724.  
  725.             }
  726.  
  727.             Alert alert = new Alert(AlertType.WARNING);
  728.             alert.setTitle("CONNECTION ERROR");
  729.             alert.setHeaderText("CONNECTION FAILED");
  730.             Console.setStyle("-fx-text-inner-color: red");
  731.  
  732.  
  733.  
  734.             Console.setText(Console.getText() + "CONNECTION FAILED TO HOSTNAME: \n" + IP + " ");
  735.  
  736.             Image img = new Image("/Images/download.jpg");
  737.             Notifications notificationBuilder = Notifications.create()
  738.  
  739.                     .title("EzyFTP")
  740.                     .text("Connection to server   " + IP + "   Failed....")
  741.                     .graphic(new ImageView(img))
  742.                     .hideAfter(Duration.seconds(5))
  743.                     .position(Pos.BOTTOM_RIGHT)
  744.                     .onAction(new EventHandler<ActionEvent>() {
  745.  
  746.                         @Override
  747.                         public void handle(ActionEvent event) {
  748.                             System.out.print("Notification was clicked");
  749.  
  750.                         }
  751.  
  752.                     });
  753.             notificationBuilder.show();
  754.             ConsoleUpdate();
  755.  
  756.  
  757.  
  758.  
  759.  
  760.  
  761.  
  762.  
  763.  
  764.  
  765.             if (CHUGONTHATMILKBOY=="TRUE") {
  766.                 alert.setContentText(" \n Connection has failed NULL (you didn't specify host address.....) due to incorrect field properties, please insure that you have entered all the correct info in, and make sure you have an active internet connection");
  767.  
  768.             }
  769.             else
  770.             {
  771.  
  772.                 alert.setContentText(" \n Connection has failed " + IP +  " due to incorrect field properties, please insure that you have entered all the correct info in, and make sure you have an active internet connection");
  773.  
  774.             }
  775.  
  776.  
  777.  
  778.  
  779.             alert.showAndWait();
  780.  
  781.             Console.textProperty().addListener(new ChangeListener<Object>() {
  782.                 @Override
  783.                 public void changed(ObservableValue<?> observable, Object oldValue,
  784.                                     Object newValue) {
  785.                     Console.setScrollTop(Double.MAX_VALUE);
  786.  
  787.                 }
  788.             });
  789.  
  790.             Console.appendText("");
  791.         }
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798.  
  799.  
  800.  
  801.         // I know why, cause 'Sysfile' is not a valid URL no matter what cause the URl does not contain the Username and pass oof stupid me but then I cannot test password or username...
  802.  
  803.  
  804.  
  805.  
  806.  
  807.  
  808.  
  809.  
  810.  
  811.  
  812.  
  813.  
  814.  
  815.  
  816.  
  817.  
  818.  
  819.  
  820.  
  821.  
  822.     }
  823.  
  824.  
  825.  
  826.  
  827.  
  828.  
  829.  
  830.  
  831.     //tell console to scroll to bottom
  832.     public void ConsoleUpdate() {
  833.         Console.textProperty().addListener(new ChangeListener<Object>() {
  834.             @Override
  835.             public void changed(ObservableValue<?> observable, Object oldValue,
  836.                                 Object newValue) {
  837.                 Console.setScrollTop(Double.MAX_VALUE);
  838.  
  839.             }
  840.         });
  841.  
  842.         Console.appendText("");
  843.     }
  844.  
  845.  
  846.     //starting attempts
  847.     public int Attempts = 20;
  848.     //repeat the ConnectionTick function, which checks server connection
  849.  
  850.     public void RepeteTick(){
  851.  
  852.  
  853.         class RepeteTick extends TimerTask {
  854.  
  855.  
  856.  
  857.  
  858.             public void run() {
  859.                 if (Attempts>0) {
  860.                     if (disconnect>0) {
  861.                         ConnectionTick();
  862.  
  863.                     }
  864.                     else
  865.                     {
  866.                         if (DisconnectMSGDisplayed==1) {
  867.                             String IP = TxtHost.getText();
  868.                             Console.setStyle("-fx-text-inner-color: red");
  869.  
  870.                             Console.setText(Console.getText() + "\n ");
  871.                             Console.setText(Console.getText() + "Clearing...\n");
  872.  
  873.                             Console.setText("");
  874.                             Console.setText(Console.getText() + " Disconnected from " + IP + "");
  875.  
  876.  
  877.                             DisconnectMSGDisplayed--;
  878.  
  879.                         }
  880.  
  881.  
  882.                     }
  883.  
  884.  
  885.  
  886.  
  887.  
  888.  
  889.                 }
  890.  
  891.             }
  892.         }
  893.  
  894.  
  895.  
  896.  
  897.         if (disconnect>0) {
  898.             Timer timer = new Timer();
  899.             timer.schedule(new RepeteTick(), 0, 5000);
  900.  
  901.         }
  902.  
  903.  
  904.  
  905.  
  906.  
  907.  
  908.     }
  909.  
  910.  
  911.  
  912.  
  913.     public int DisconnectMSGDisplayed = 1;
  914.  
  915.     public void Disconnect(ActionEvent event) {
  916.  
  917.         if(UsernameLabel.getText().equals("(not connected) ")){
  918.  
  919.  
  920.             Console.setStyle("-fx-text-inner-color: orange");
  921.             Console.setText(Console.getText() + " No connected to a server has been established ");
  922.             ConsoleUpdate();
  923.  
  924.         }
  925.         else
  926.         {
  927.  
  928.             Console.setStyle("-fx-text-inner-color: orange");
  929.             Console.setText(Console.getText() + " Disconnecting..... ");
  930.             UsernameLabel.setTextFill(Color.web("0x0000FF"));
  931.  
  932.             PasswordLabel.setTextFill(Color.web("0x0000FF"));
  933.  
  934.             UsernameLabel.setText("Disconnected");
  935.  
  936.             PasswordLabel.setText("Disconnected");
  937.  
  938.             disconnect--;
  939.  
  940.             ConsoleUpdate();
  941.  
  942.         }
  943.  
  944.  
  945.  
  946.  
  947.  
  948.  
  949.  
  950.  
  951.     }
  952.     //check connection to server every 5 seconds :)
  953.     public void ConnectionTick(){
  954.         //define Strings to inputs/textfields
  955.         String Username = TxtUsername.getText();
  956.         String Password = TxtPassword.getText();
  957.         String IP = TxtHost.getText();
  958.  
  959.         setDllLibraryPath("C:\\Users\\admin\\Desktop\\DLL PATH");
  960.  
  961.         //text chilkat lib
  962.  
  963.         try {
  964.             System.load("C:\\Users\\admin\\Desktop\\DLL PATH\\chilkat.dll");
  965.         } catch (UnsatisfiedLinkError e) {
  966.             System.err.println("Native code library failed to load.\n" + e);
  967.  
  968.         }
  969.  
  970.  
  971.  
  972.  
  973.         // create chilkat FTP connection for testing (only for testing)
  974.         CkFtp2 ftp = new CkFtp2();
  975.  
  976.         boolean success;
  977.  
  978.         if (disconnect<=0) {
  979.             ftp.Disconnect();
  980.  
  981.         }
  982.  
  983.  
  984.  
  985.  
  986.  
  987.  
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.  
  995.  
  996.  
  997.  
  998.         //specify IP, Username and Host for connection
  999.         ftp.put_Hostname(IP);
  1000.         ftp.put_Username(Username);
  1001.         ftp.put_Password(Password);
  1002.  
  1003.  
  1004.  
  1005.  
  1006.         //define 'success'...
  1007.         success = ftp.Connect();
  1008.         //if connection is successful
  1009.         if (success == true) {
  1010.  
  1011.  
  1012.             i++;
  1013.             int AttemptedReconnect = 0;
  1014.             int Attempts = 20;
  1015.  
  1016.  
  1017.  
  1018.  
  1019.  
  1020.  
  1021.  
  1022.  
  1023.  
  1024.  
  1025.             //Console.setText("Ticked Connection to " + IP + " Was successful ");
  1026.             Console.setStyle("-fx-text-inner-color: green");
  1027.  
  1028.             if (i == 1) {
  1029.  
  1030.  
  1031.                 Console.setText(Console.getText() + "\n ");
  1032.                 Console.setText(Console.getText() + "connection Checked:" + IP + " for the " + i + "st time  \n");
  1033.  
  1034.             }
  1035.             if(i == 2) {
  1036.                 Console.setText(Console.getText() + "\n ");
  1037.  
  1038.  
  1039.                 Console.setText(Console.getText() + "connection Checked: " + IP + " for the " + i + "nd time \n ");
  1040.  
  1041.             }
  1042.             if(i == 3) {
  1043.                 Console.setText(Console.getText() + "\n ");
  1044.  
  1045.  
  1046.                 Console.setText(Console.getText() + "connection Checked: " + IP + " for the " + i + "rd time \n");
  1047.  
  1048.             }
  1049.             if(i>= 4) {
  1050.                 Console.setText(Console.getText() + "\n ");
  1051.  
  1052.  
  1053.                 Console.setText(Console.getText() + "connection Checked: " + IP + " for the " + i + "th time \n");
  1054.  
  1055.             }
  1056.  
  1057.  
  1058.             ConsoleUpdate();
  1059.  
  1060.  
  1061.         }
  1062.         //if it isn't
  1063.         else
  1064.         {
  1065.             System.out.print(ftp.lastErrorText());
  1066.  
  1067.  
  1068.             Console.setStyle("-fx-text-inner-color: red");
  1069.  
  1070.  
  1071.  
  1072.  
  1073.             if (AttemptedReconnect>0 && Attempts>0) {
  1074.                 Attempts--;
  1075.  
  1076.  
  1077.                 Console.setText(Console.getText() + "\n ");
  1078.  
  1079.                 Console.setText(Console.getText() + "Attempt at reconnecting to " + IP + "Failed.... " + Attempts + " attempts remaining!");
  1080.  
  1081.  
  1082.                 UsernameLabel.setTextFill(Color.web("FF8C00"));
  1083.                 PasswordLabel.setTextFill(Color.web("FF8C00"));
  1084.  
  1085.  
  1086.  
  1087.  
  1088.                 UsernameLabel.setText("Contended");
  1089.  
  1090.                 PasswordLabel.setText("Contended");
  1091.  
  1092.  
  1093.  
  1094.             }
  1095.  
  1096.             if(Attempts>0) {
  1097.  
  1098.  
  1099.                 Console.setText(Console.getText() + "\n ");
  1100.                 Console.setText(Console.getText() + "Connection to  \n" + IP + " is no longer active, please ensure you have an active internet connection and that the FTP server is up...");
  1101.                 Console.setText(Console.getText() + "\n ");
  1102.                 Console.setText(Console.getText() + "Attempting reconnect to \n" + IP + " ");
  1103.                 AttemptedReconnect++;
  1104.                 UsernameLabel.setTextFill(Color.web("FF8C00"));
  1105.                 PasswordLabel.setTextFill(Color.web("FF8C00"));
  1106.  
  1107.  
  1108.  
  1109.  
  1110.                 UsernameLabel.setText("Contended");
  1111.  
  1112.                 PasswordLabel.setText("Contended");
  1113.  
  1114.  
  1115.             }
  1116.             else
  1117.             {
  1118.  
  1119.  
  1120.  
  1121.                 Console.setText(Console.getText() + "\n ");
  1122.                 Console.setText(Console.getText() + " Attempts have timed out, please manually reinitialise connection to the server ");
  1123.  
  1124.                 UsernameLabel.setStyle("-fx-text-inner-color: red");
  1125.  
  1126.                 PasswordLabel.setStyle("-fx-text-inner-color: red");
  1127.  
  1128.                 UsernameLabel.setText("*invalid*");
  1129.  
  1130.                 PasswordLabel.setText("*invalid");
  1131.  
  1132.  
  1133.                 Label.setText("Connection has officially timed out");
  1134.  
  1135.                 Notifications notificationBuilder = Notifications.create()
  1136.  
  1137.                         .title("EzyFTP")
  1138.                         .text("Connection to " + IP + " has timed out....")
  1139.                         .graphic(null)
  1140.                         .hideAfter(Duration.seconds(5))
  1141.                         .position(Pos.BOTTOM_RIGHT)
  1142.                         .onAction(new EventHandler<ActionEvent>() {
  1143.  
  1144.                             @Override
  1145.                             public void handle(ActionEvent event) {
  1146.                                 System.out.print("S");
  1147.  
  1148.  
  1149.                             }
  1150.  
  1151.                         });
  1152.                 notificationBuilder.show();
  1153.  
  1154.             }
  1155.  
  1156.  
  1157.             ConsoleUpdate();
  1158.         }
  1159.  
  1160.  
  1161.  
  1162.     }
  1163.  
  1164.  
  1165.  
  1166.  
  1167.  
  1168.  
  1169.  
  1170.  
  1171.  
  1172.  
  1173.  
  1174.  
  1175.  
  1176.  
  1177.  
  1178.         //looks like I am going to have to find a way to solve this myself, but for now, ima go do something else, hope anyone who has watched the stream has enjoyed it so far and watching me be a retard, but I am new to Java so expect to see some improvements. For now, Cya..
  1179.  
  1180.  
  1181.  
  1182.  
  1183.  
  1184.  
  1185.  
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.  
  1193.  
  1194.  
  1195.  
  1196.  
  1197.  
  1198.  
  1199.     //check what has been left empty
  1200.     public void CheckFields() {
  1201.  
  1202.         if (TxtUsername.getText().equals("")) {
  1203.             Label.setText("Connection Failed");
  1204.             Alert alert = new Alert(AlertType.WARNING);
  1205.             alert.setTitle("!!!!Error!!!!");
  1206.             alert.setHeaderText("Error");
  1207.             alert.setContentText(" \n No Username provided");
  1208.  
  1209.             alert.showAndWait();
  1210.             System.out.print(" \n Username Null Error...");
  1211.         }
  1212.  
  1213.         if (TxtPassword.getText().equals("")) {
  1214.             Label.setText("Connection Failed");
  1215.             Alert alert = new Alert(AlertType.WARNING);
  1216.             alert.setTitle("!!!!Error!!!!");
  1217.             alert.setHeaderText("Error");
  1218.             alert.setContentText(" \n No Password provided");
  1219.  
  1220.             alert.showAndWait();
  1221.  
  1222.             System.out.print(" \n Password Null Error...");
  1223.  
  1224.         }
  1225.         if (TxtHost.getText().equals("")) {
  1226.             Label.setText("Connection Failed");
  1227.             Alert alert = new Alert(AlertType.WARNING);
  1228.             alert.setTitle("!!!!Error!!!!");
  1229.             alert.setHeaderText("Error");
  1230.             alert.setContentText(" \n No host IP provided");
  1231.  
  1232.             alert.showAndWait();
  1233.  
  1234.             System.out.print("\n Host Null Error...");
  1235.  
  1236.         }
  1237.  
  1238.         if (Port.getText().equals("")) {
  1239.             Label.setText("Connection Failed");
  1240.             Alert alert = new Alert(AlertType.WARNING);
  1241.             alert.setTitle("!!!!Error!!!!");
  1242.             alert.setHeaderText("Error");
  1243.             alert.setContentText("\n No port specified");
  1244.  
  1245.             alert.showAndWait();
  1246.  
  1247.             System.out.print("\n Port Null Error...");
  1248.  
  1249.         }
  1250.  
  1251.  
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.  
  1259.  
  1260.  
  1261.  
  1262.  
  1263.  
  1264.  
  1265.  
  1266.  
  1267.  
  1268.  
  1269.  
  1270.  
  1271.  
  1272.  
  1273.  
  1274.  
  1275.  
  1276.  
  1277.  
  1278.  
  1279.  
  1280.  
  1281.  
  1282.  
  1283.     }
  1284.  
  1285.  
  1286.  
  1287.  
  1288.     //when SSL only checkbox is selected
  1289.     public void SSLSelected(ActionEvent event) {
  1290.  
  1291.  
  1292.     }
  1293.  
  1294.  
  1295.  
  1296. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement