Add admission to download files
This commit is contained in:
parent
bc0aa22a24
commit
5f76f74c16
17
src/main/java/ftp/sar/FileChooser.java
Normal file
17
src/main/java/ftp/sar/FileChooser.java
Normal file
@ -0,0 +1,17 @@
|
||||
package ftp.sar;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class FileChooser {
|
||||
|
||||
public String getPathToSave() {
|
||||
JFileChooser fileChooser = new JFileChooser();
|
||||
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||||
fileChooser.setDialogTitle("Choose file destination");
|
||||
fileChooser.setAcceptAllFileFilterUsed(false);
|
||||
fileChooser.showSaveDialog(null);
|
||||
|
||||
return fileChooser.getSelectedFile().toString();
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package ftp.sar.controller;
|
||||
|
||||
import ftp.sar.FileChooser;
|
||||
import ftp.sar.builder.FilePaneBuilder;
|
||||
import ftp.sar.exception.CannotConnectException;
|
||||
import ftp.sar.server.Server;
|
||||
@ -8,6 +9,7 @@ import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.scene.layout.FlowPane;
|
||||
import javafx.scene.layout.Pane;
|
||||
|
||||
@ -61,10 +63,22 @@ public class ServerPanelController implements Initializable {
|
||||
for (String filename : this.server.getFileList()) {
|
||||
var pane = this.filePaneBuilder.getPane(filename);
|
||||
|
||||
pane.addEventHandler(MouseEvent.MOUSE_CLICKED, mouseEvent -> this.getFile(filename));
|
||||
|
||||
this.fileContainer.getChildren().add(pane);
|
||||
}
|
||||
}
|
||||
|
||||
private void getFile(String filename) {
|
||||
FileChooser fileChooser = new FileChooser();
|
||||
String path = fileChooser.getPathToSave();
|
||||
|
||||
this.server.getConnector().getFile(filename, path);
|
||||
|
||||
System.out.println(filename);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||
}
|
||||
|
@ -77,4 +77,46 @@ public class ServerConnector {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void getFile(String filename, String path) {
|
||||
File file = new File(path + "\\" + filename);
|
||||
try {
|
||||
this.sendRequest("FTP_" + filename);
|
||||
} catch (CannotConnectException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
DataInputStream dataInputStream = null;
|
||||
char[] buffer = new char[512];
|
||||
try {
|
||||
dataInputStream = new DataInputStream(this.server.getSocket().getInputStream());
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(dataInputStream);
|
||||
BufferedReader reader = new BufferedReader(inputStreamReader);
|
||||
|
||||
reader.read(buffer);
|
||||
|
||||
String l = "";
|
||||
|
||||
for (char c: buffer) {
|
||||
if (Character.isDigit(c)) {
|
||||
l += c;
|
||||
}
|
||||
}
|
||||
//TODO: Finish getting file
|
||||
// long lengthOFFile = Long.parseLong(l.trim());
|
||||
//
|
||||
//
|
||||
// byte[] fileBuffer = new byte[4096];
|
||||
//
|
||||
// do {
|
||||
// dataInputStream.read(fileBuffer);
|
||||
// lengthOFFile -= 4096;
|
||||
// } while (lengthOFFile > 0);
|
||||
|
||||
System.out.println(l);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user