Skip to content

Commit

Permalink
Adding directory to the FTP and QOL stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
DomAtTheShack committed Jun 5, 2023
1 parent 79e0439 commit 3f76da7
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 13 deletions.
Binary file modified out/production/Dom-s-FTP-Client/FTPClientJ.class
Binary file not shown.
Binary file modified out/production/Dom-s-FTP-Client/FileBrowserGUI$1.class
Binary file not shown.
Binary file modified out/production/Dom-s-FTP-Client/FileBrowserGUI$2.class
Binary file not shown.
Binary file modified out/production/Dom-s-FTP-Client/FileBrowserGUI.class
Binary file not shown.
14 changes: 7 additions & 7 deletions src/FTPClientJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ public static boolean connect(String server,String user, String pass,int port) t
ftpClient.connect(server, port);
int replyCode = ftpClient.getReplyCode();
if (!FTPReply.isPositiveCompletion(replyCode)) {
Main.loadingBar.addConsoleText("FTP server refused connection.");
Main.gui.addConsoleText("FTP server refused connection.");
return false;
}
boolean loggedIn = ftpClient.login(user, pass);
if (!loggedIn) {
Main.loadingBar.addConsoleText("Could not log in to the FTP server.");
Main.gui.addConsoleText("Could not log in to the FTP server.");
return false;
}
return true;
}catch (Exception e){
Main.loadingBar.addConsoleText(e.toString());
Main.gui.addConsoleText(e.toString());
return false;
}
}
public static void disconnect() throws IOException {
try {
ftpClient.disconnect();
}catch(Exception e){
Main.loadingBar.addConsoleText(e.toString());
Main.gui.addConsoleText(e.toString());
}
}
public static boolean FTPUpFile(String sendFile, String remoteDir) {
Expand All @@ -66,9 +66,9 @@ public static boolean FTPUpFile(String sendFile, String remoteDir) {
totalBytesUploaded += bytesRead;

int percentComplete = (int) ((totalBytesUploaded * 100) / fileSize);
Main.loadingBar.setLoadingBar(percentComplete);
Main.gui.setLoadingBar(percentComplete);
}
Main.loadingBar.setLoadingBarText("Done!");
Main.gui.setLoadingBarText("Done!");

bufferedInputStream.close();
fileInputStream.close();
Expand All @@ -78,7 +78,7 @@ public static boolean FTPUpFile(String sendFile, String remoteDir) {
System.out.println("File upload completed successfully.");
return true;
} catch (Exception e) {
Main.loadingBar.addConsoleText(e.toString());
Main.gui.addConsoleText(e.toString());
} finally {
try {
if (fileInputStream != null) {
Expand Down
21 changes: 17 additions & 4 deletions src/FileBrowserGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;

public class FileBrowserGUI extends JFrame {
private JList<String> fileList;
Expand All @@ -17,7 +18,7 @@ public class FileBrowserGUI extends JFrame {
private JProgressBar loadingBar;
private JTextField textField1;
private JTextField textField2;
private JTextField textField3;
private JPasswordField textField3;
private JTextField textField4;
private JTextArea console;

Expand Down Expand Up @@ -75,7 +76,7 @@ public FileBrowserGUI() {
JLabel label2 = new JLabel("Username");
textField2 = new JTextField(20);
JLabel label3 = new JLabel("Password");
textField3 = new JTextField(20);
textField3 = new JPasswordField(20);
JLabel label4 = new JLabel("Port");
textField4 = new JTextField(5);

Expand Down Expand Up @@ -171,10 +172,11 @@ public void valueChanged(ListSelectionEvent e) {
@Override
public void actionPerformed(ActionEvent e) {
try {
String pass = new String(textField3.getPassword());
if(textField1.getText().equals("")||(textField4.getText()).equals("")){
addConsoleText("Invalid Server Info Input");
}else {
if(FTPClientJ.connect(textField1.getText(), textField2.getText(), textField3.getText(), Integer.parseInt(textField4.getText()))){
if(FTPClientJ.connect(textField1.getText(), textField2.getText(), pass, Integer.parseInt(textField4.getText()))){
addConsoleText("Connected!");
connectButton.setEnabled(false);
disconnectButton.setEnabled(true);
Expand All @@ -195,6 +197,7 @@ public void actionPerformed(ActionEvent e) {
FTPClientJ.disconnect();
connectButton.setEnabled(true);
disconnectButton.setEnabled(false);
addConsoleText("Disconnected!");
} catch (IOException ex) {
addConsoleText(ex.toString());
}
Expand All @@ -211,7 +214,17 @@ public void actionPerformed(ActionEvent e) {
button2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// performButton2Action();
((DefaultListModel<String>) ftpDirectoryList.getModel()).clear();
File[] files = currentDirectory.listFiles();
if (files != null) {
for (File file : files) {
if (file.isFile()) {
((DefaultListModel<String>) ftpDirectoryList.getModel()).addElement(file.getName());
}else {
((DefaultListModel<String>) ftpDirectoryList.getModel()).addElement(file.getName()+ File.separator);
}
}
}
}
});

Expand Down
4 changes: 2 additions & 2 deletions src/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import javax.swing.*;

public class Main {
public static FileBrowserGUI loadingBar;
public static FileBrowserGUI gui;

static {
loadingBar = new FileBrowserGUI();
gui = new FileBrowserGUI();
}

public static void main(String[] args){
Expand Down

0 comments on commit 3f76da7

Please sign in to comment.