Skip to content
Snippets Groups Projects
Commit fd9c34cf authored by Hocine Bouali's avatar Hocine Bouali
Browse files

ajout des methodes pour agentFlopBox

parent 0e7334cd
No related branches found
No related tags found
No related merge requests found
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
<groupId>org.glassfish.jersey.media</groupId> <groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId> <artifactId>jersey-media-multipart</artifactId>
<version>2.33</version> <version>2.33</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
......
...@@ -175,6 +175,44 @@ public class ServiceFTPEndPoint { ...@@ -175,6 +175,44 @@ public class ServiceFTPEndPoint {
return Response.ok(file).header("Content-Disposition", "attachment; filename=\"" + filename + "\"").build(); return Response.ok(file).header("Content-Disposition", "attachment; filename=\"" + filename + "\"").build();
} }
@GET
@Secured
@Path("{alias}/file/last-modified/{path: .*}")
@Produces(MediaType.TEXT_PLAIN)
public Response getLastDateFile(@PathParam("alias") String alias, @PathParam("path") String path,
@DefaultValue("anonymous") @HeaderParam("username") String username,
@DefaultValue("anonymous") @HeaderParam("password") String psw,
@DefaultValue("pasv") @HeaderParam("mode") String mode,
@DefaultValue("FTPS") @HeaderParam("type") String type, @DefaultValue("21") @HeaderParam("port") int port) {
Response r = init(alias, type, username, psw, mode, port);
if (!(r.getStatus() == Response.Status.ACCEPTED.getStatusCode())) {// on verifie que l'init s'est bien passer
return r;
}
String date;
try {
date = ftp.getModificationTime(path);
if(date ==null) {
return Response.status(Response.Status.FORBIDDEN)
.entity("file " + path + " not exist on the ftp server ")
.build();
}
System.out.println(date);
} catch (IOException e) {
return Response.status(Response.Status.FORBIDDEN)
.entity("file " + path + " not exist on the ftp server or you don't have the right to download it")
.build();
} finally {
try {
ftp.disconnect();
} catch (IOException e) {
}
}
return Response.ok(date).build();
}
/* /*
* Méthode non fonctionnel qui permet de récuperer un dossier, de le zipper et * Méthode non fonctionnel qui permet de récuperer un dossier, de le zipper et
* de l'envoyer au client * de l'envoyer au client
...@@ -353,6 +391,42 @@ public class ServiceFTPEndPoint { ...@@ -353,6 +391,42 @@ public class ServiceFTPEndPoint {
return Response.ok("successfully renamed to " + rename).build(); return Response.ok("successfully renamed to " + rename).build();
} }
@PUT
@Secured
@Path("{alias}/relocate/{path: .*}")
@Produces(MediaType.TEXT_PLAIN)
public Response relocate(@PathParam("alias") String alias, @PathParam("path") String path,
@DefaultValue("anonymous") @HeaderParam("username") String username,
@DefaultValue("anonymous") @HeaderParam("password") String psw,
@DefaultValue("pasv") @HeaderParam("mode") String mode,
@DefaultValue("FTP") @HeaderParam("type") String type, @QueryParam("to") String rename,
@DefaultValue("21") @HeaderParam("port") int port) {
Response r = init(alias, type, username, psw, mode, port);
if (!(r.getStatus() == Response.Status.ACCEPTED.getStatusCode())) {// on verifie que l'init s'est bien passer
return r;
}
// if (path.endsWith("/")) {
// path = path.substring(0, path.length() - 1);
// }
try {
if (!ftp.rename(path, rename)) {
return Response.status(Response.Status.BAD_REQUEST).build();
}
} catch (IOException e) {
return Response.status(Response.Status.FORBIDDEN).entity("can't rename one file " + path + "!").build();
} finally {
try {
ftp.disconnect();
} catch (IOException e) {
}
}
return Response.ok("successfully renamed to " + rename).build();
}
/** /**
* Methode qui permet d'upload un fichier sur le serveur, pour envoyer un * Methode qui permet d'upload un fichier sur le serveur, pour envoyer un
* dossier,il faut prealablement le zipper * dossier,il faut prealablement le zipper
......
...@@ -8,6 +8,7 @@ import java.io.FileOutputStream; ...@@ -8,6 +8,7 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.SocketException; import java.net.SocketException;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
...@@ -15,7 +16,7 @@ import java.util.Map; ...@@ -15,7 +16,7 @@ import java.util.Map;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
import org.apache.commons.net.PrintCommandListener;
import org.apache.commons.net.ftp.FTP; import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile; import org.apache.commons.net.ftp.FTPFile;
...@@ -45,6 +46,8 @@ public class Utils { ...@@ -45,6 +46,8 @@ public class Utils {
if (file.isDirectory()) { if (file.isDirectory()) {
details = "[" + details + "]"; details = "[" + details + "]";
}else {
details = "<" + details + ">";
} }
details += " " + file.getSize(); details += " " + file.getSize();
details += " " + file.getUser(); details += " " + file.getUser();
...@@ -180,6 +183,7 @@ public class Utils { ...@@ -180,6 +183,7 @@ public class Utils {
f.login(username, psw); f.login(username, psw);
f.sendCommand("PBSZ 0"); f.sendCommand("PBSZ 0");
f.sendCommand("PROT P"); f.sendCommand("PROT P");
f.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
if (mode.equals("pasv")) { if (mode.equals("pasv")) {
f.enterLocalPassiveMode(); f.enterLocalPassiveMode();
} else if (!mode.equals("port")) { } else if (!mode.equals("port")) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment