Skip to content
Snippets Groups Projects
Commit 063a2bcd authored by nguyen's avatar nguyen
Browse files

changement d'appel au listing de dossier, et de téléchargement de fichier

parent 728f622e
Branches
Tags
No related merge requests found
...@@ -215,4 +215,14 @@ public class FtpClient extends FTP { ...@@ -215,4 +215,14 @@ public class FtpClient extends FTP {
throw new FTPServerException("Error deleting folder."); throw new FTPServerException("Error deleting folder.");
} }
} }
public boolean createDirectory(String pathFolder) throws FTPServerException {
try {
return this.getClient().makeDirectory(pathFolder);
}
catch (IOException e) {
throw new FTPServerException("Error deleting folder.");
}
}
} }
...@@ -79,7 +79,7 @@ public class ResourceFile { ...@@ -79,7 +79,7 @@ public class ResourceFile {
} }
@GET @GET
@Path("{name}/list/{path: .*}") @Path("{name}/{path: .*}")
@Produces(MediaType.TEXT_PLAIN) @Produces(MediaType.TEXT_PLAIN)
public Response list(@PathParam("name") String server, @PathParam("path") String pathFile, @HeaderParam("username") String username, @HeaderParam("password") String password, @HeaderParam("port") int port) { public Response list(@PathParam("name") String server, @PathParam("path") String pathFile, @HeaderParam("username") String username, @HeaderParam("password") String password, @HeaderParam("port") int port) {
if(!validServer(server)) { if(!validServer(server)) {
...@@ -118,7 +118,7 @@ public class ResourceFile { ...@@ -118,7 +118,7 @@ public class ResourceFile {
// je passe apres manger a download, upload des fichiers. // je passe apres manger a download, upload des fichiers.
// pour la ressource Fichier // pour la ressource Fichier
@GET @GET
@Path("{name}/{path: .*}") @Path("{name}/file/{path: .*}")
@Produces({MediaType.APPLICATION_OCTET_STREAM, MediaType.TEXT_PLAIN}) @Produces({MediaType.APPLICATION_OCTET_STREAM, MediaType.TEXT_PLAIN})
public Response download(@PathParam("name") String server, @PathParam("path") String pathFile, @HeaderParam("username") String username, @HeaderParam("password") String password, @HeaderParam("port") int port) { public Response download(@PathParam("name") String server, @PathParam("path") String pathFile, @HeaderParam("username") String username, @HeaderParam("password") String password, @HeaderParam("port") int port) {
if(!validServer(server)) { if(!validServer(server)) {
...@@ -309,5 +309,50 @@ public class ResourceFile { ...@@ -309,5 +309,50 @@ public class ResourceFile {
return this.response.build(); return this.response.build();
} }
@POST
@Path("{name}/directory/{path: .*}")
@Produces(MediaType.TEXT_PLAIN)
public Response createFolder(@PathParam("name") String server, @PathParam("path") String pathFile, @HeaderParam("username") String username, @HeaderParam("password") String password, @HeaderParam("port") int port) {
System.out.println("Fonction creation d'un dossier");
if(!validServer(server)) {
loadResponse(404, "Erreur serveur non valide.\n");
return this.response.build();
}
if(port == 0) {
port = 21;
}
try {
FtpClient userClient = new FtpClient(listServer.get(server), port, username, password);
System.out.println("server, username, password, port : "+ listServer.get(server) + username + password + port + "\n");
userClient.connect();
userClient.login();
// "/home/zomdex/Documents/MASTER_GL_1/Semestre 2b/SR2/sr2-projet1-flopbox/" pour le locahost
if (userClient.createDirectory(pathFile)) {
loadResponse(200, "Dossier crée.\n");
}
else {
loadResponse(404, "Impossible de crée le dossier.\n");
}
userClient.logout();
userClient.disconnectClient();
}
catch (ConnectionServerException e) {
loadResponse(403, "Erreur connection au serveur FTP refusé.\n");
}
catch (FTPServerException e) {
loadResponse(503, "Erreur problème avec le serveur FTP.\n");
}
catch (LoginException e) {
loadResponse(403, "Erreur login ou mot de passe incorrect.\n");
}
catch (LogoutException e) {
loadResponse(503, "Erreur lors de la déconnexion du serveur FTP.\n");
}
return this.response.build();
}
} }
...@@ -14,16 +14,16 @@ curl --location --request GET 'http://localhost:8080/flopbox/alias2' ...@@ -14,16 +14,16 @@ curl --location --request GET 'http://localhost:8080/flopbox/alias2'
List : List :
curl --location --request GET 'http://localhost:8080/flopbox/alias1/list/' --header 'username: anonymous' --header 'password: 1234' --header 'port: 21' curl --location --request GET 'http://localhost:8080/flopbox/alias1/' --header 'username: anonymous' --header 'password: 1234' --header 'port: 21'
curl --location --request GET 'http://localhost:8080/flopbox/alias2/list/' --header 'username: nguyen' --header 'password: 6c7667d323' --header 'port: 21' curl --location --request GET 'http://localhost:8080/flopbox/alias2/' --header 'username: nguyen' --header 'password: 6c7667d323' --header 'port: 21'
Download : Download :
curl --location --request GET 'http://localhost:8080/flopbox/alias1/cloud-images/FOOTER.html' --header 'username: anonymous' --header 'password: 1234' --header 'port: 21' -o TEST1.txt curl --location --request GET 'http://localhost:8080/flopbox/alias1/file/cloud-images/FOOTER.html' --header 'username: anonymous' --header 'password: 1234' --header 'port: 21' -o TEST1.txt
curl --location --request GET 'http://localhost:8080/flopbox/alias2/TEST.txt' --header 'username: nguyen' --header 'password: 6c7667d323' --header 'port: 21' -o TEST2.txt curl --location --request GET 'http://localhost:8080/flopbox/alias2/file/TEST.txt' --header 'username: nguyen' --header 'password: 6c7667d323' --header 'port: 21' -o TEST2.txt
Upload : Upload :
...@@ -33,9 +33,13 @@ curl -v -X POST -F file=@image.jpg --header 'username: nguyen' --header 'passwo ...@@ -33,9 +33,13 @@ curl -v -X POST -F file=@image.jpg --header 'username: nguyen' --header 'passwo
Rename : Rename :
curl -v -X PUT --head.jpg' --header 'username: nguyen' --header 'password: 6c7667d323' http://localhost:8080/flopbox/alias2/image.jpg curl -v -X PUT --header 'rename: image2.jpg' --header 'username: nguyen' --header 'password: 6c7667d323' http://localhost:8080/flopbox/alias2/image.jpg
Delete folder : Delete folder :
curl -v -X DELETE --header 'username: anonymous' --header 'password: 67d323' http://localhost:8080/flopbox/alias1/releases curl -v -X DELETE --header 'username: anonymous' --header 'password: 67d323' http://localhost:8080/flopbox/alias1/releases
Create folder :
curl -v -X POST --header 'username: nguyen' --header 'password: 6c7667d323' http://localhost:8080/flopbox/alias2/coucou
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment