Skip to content

Commit

Permalink
Updated GUI with working crude FTP Client
Browse files Browse the repository at this point in the history
  • Loading branch information
DomAtTheShack committed Jun 3, 2023
1 parent f429e68 commit 1fe3e6c
Show file tree
Hide file tree
Showing 23 changed files with 168 additions and 52 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/libraries/commons_net_3_9_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/libraries/commons_net_3_9_0__2_.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions Dom-s-FTP-Client.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="commons-net-3.9.0" level="project" />
<orderEntry type="library" name="commons-net-3.9.0 (2)" level="project" />
</component>
</module>
Binary file added out/production/Dom-s-FTP-Client/FTPClientJ.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added out/production/Dom-s-FTP-Client/icons/arrow_left.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions src/FTPClientJ.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import org.apache.commons.net.ftp.FTPClient;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class FTPClientJ {

public static void main(String[] args) {
String server = "192.168.5.118";
int port = 21;
String username = "dominichann";
String password = "Hidom@123";
String localFilePath = "C:\\users\\dooli\\Downloads\\rename.bat";
String remoteDirectory = "/home/dominichann/";

FTPClient ftpClient = new FTPClient();

try {
ftpClient.connect(server, port);
boolean loggedIn = ftpClient.login(username, password);

if (loggedIn) {
System.out.println("Logged in to FTP server.");

//ftpClient.enterLocalPassiveMode();
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);

File localFile = new File(localFilePath);
FileInputStream inputStream = new FileInputStream(localFile);

boolean uploaded = ftpClient.storeFile(remoteDirectory + localFile.getName(), inputStream);
inputStream.close();

if (uploaded) {
System.out.println("File uploaded successfully.");
} else {
System.out.println("Failed to upload the file.");
}

ftpClient.logout();
ftpClient.disconnect();
} else {
System.out.println("Failed to log in to FTP server.");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
69 changes: 62 additions & 7 deletions src/FileBrowserGUI.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.*;
Expand All @@ -22,15 +23,19 @@ public class FileBrowserGUI extends JFrame {
private File currentDirectory;

public FileBrowserGUI() {
setTitle("File Browser");
setTitle("FTP Client");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(500, 400);
setSize(600, 400);

JPanel contentPane = new JPanel(new BorderLayout());
contentPane.setBorder(new EmptyBorder(10, 10, 10, 10));
setContentPane(contentPane);

listModel = new DefaultListModel<>();
fileList = new JList<>(listModel);

JScrollPane scrollPane = new JScrollPane(fileList);
add(scrollPane, BorderLayout.CENTER);
contentPane.add(scrollPane, BorderLayout.CENTER);

backButton = new JButton(getIcon("arrow_left.png"));
backButton.setEnabled(false);
Expand All @@ -57,7 +62,46 @@ public void actionPerformed(ActionEvent e) {
buttonPanel.add(backButton, BorderLayout.WEST);
buttonPanel.add(selectedFileLabel, BorderLayout.CENTER);
buttonPanel.add(forwardButton, BorderLayout.EAST);
add(buttonPanel, BorderLayout.NORTH);
contentPane.add(buttonPanel, BorderLayout.NORTH);

// Create the buttons section
JPanel buttonsSection = new JPanel();
buttonsSection.setLayout(new GridLayout(3, 1));

JButton button1 = new JButton("Button 1");
button1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Define the functionality for Button 1
// Add your custom code here
JOptionPane.showMessageDialog(null, "Button 1 clicked");
}
});
buttonsSection.add(button1);

JButton button2 = new JButton("Button 2");
button2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Define the functionality for Button 2
// Add your custom code here
JOptionPane.showMessageDialog(null, "Button 2 clicked");
}
});
buttonsSection.add(button2);

JButton button3 = new JButton("Button 3");
button3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Define the functionality for Button 3
// Add your custom code here
JOptionPane.showMessageDialog(null, "Button 3 clicked");
}
});
buttonsSection.add(button3);

contentPane.add(buttonsSection, BorderLayout.EAST);

fileList.addMouseListener(new MouseAdapter() {
@Override
Expand All @@ -66,7 +110,7 @@ public void mouseClicked(MouseEvent e) {
int selectedIndex = fileList.getSelectedIndex();
if (selectedIndex != -1) {
String selectedFile = listModel.getElementAt(selectedIndex);
File file = new File(selectedFile);
File file = new File(currentDirectory, selectedFile);
if (file.isDirectory()) {
navigateToDirectory(file);
}
Expand All @@ -75,6 +119,7 @@ public void mouseClicked(MouseEvent e) {
}
});


fileList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
Expand All @@ -83,7 +128,7 @@ public void valueChanged(ListSelectionEvent e) {
if (selectedIndex != -1) {
String selectedFile = listModel.getElementAt(selectedIndex);
File file = new File(selectedFile);
selectedFileLabel.setText(file.getName());
selectedFileLabel.setText(currentDirectory.getPath()+"\\"+file.getName());
} else {
selectedFileLabel.setText("");
}
Expand All @@ -92,6 +137,7 @@ public void valueChanged(ListSelectionEvent e) {
});



backStack = new Stack<>();
forwardStack = new Stack<>();
navigateToDirectory(new File(System.getProperty("user.home")));
Expand All @@ -118,6 +164,7 @@ private void navigateToDirectory(File directory) {

updateFileList(directory);
currentDirectory = directory;
selectedFileLabel.setText(currentDirectory.getPath());
}

private void navigateBack() {
Expand All @@ -133,6 +180,8 @@ private void navigateBack() {
backButton.setEnabled(false);
}
}
selectedFileLabel.setText(currentDirectory.getPath()+"\\");

}

private void navigateForward() {
Expand All @@ -148,14 +197,20 @@ private void navigateForward() {
forwardButton.setEnabled(false);
}
}
selectedFileLabel.setText(currentDirectory.getPath()+"\\");

}

private void updateFileList(File directory) {
listModel.clear();
File[] files = directory.listFiles();
if (files != null) {
for (File file : files) {
listModel.addElement(file.getAbsolutePath());
if(file.isDirectory()){
listModel.addElement(file.getName()+"\\");
}else {
listModel.addElement(file.getName());
}
}
}
}
Expand Down
45 changes: 0 additions & 45 deletions src/Main.java

This file was deleted.

0 comments on commit 1fe3e6c

Please sign in to comment.