Skip to content
Snippets Groups Projects
Commit c88cd315 authored by Fabio Vandewaeter's avatar Fabio Vandewaeter
Browse files

save

parent d5fbc88b
No related branches found
No related tags found
No related merge requests found
......@@ -103,16 +103,28 @@ Note: Unnecessary use of -X or --request, GET is already inferred.
**Note comprise entre 11 et 12 si—en plus—le proxy FlopBox, permet de télécharger (download) et téléverser (upload) un petit fichier texte:**
- download :
- download fichier :
```shell
curl -X GET -H "Authorization: Bearer valid-token-1" http://localhost:8080/ftps/mon-ftp/test
```
- upload :
-download dossier :
```shell
curl -X GET -H "Authorization: Bearer valid-token-1" -H "X-FTP-User: user" -H "X-FTP-Pass: password" http://localhost:8080/ftps/mon-ftp/dir4 -o test.zip
unzip test.zip
```
- upload fichier :
```shell
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer valid-token-1" -d '{"alias":"mon-ftp","host":"localhost","port":2121}' http://localhost:8080/ftps
```
- upload dossier :
```shell
```
**Note comprise entre 12 et 13 si—en plus—le proxy FlopBox, permet de télécharger (download) et téléverser (upload) un gros fichier binaire (image, vidéo, etc.):**
**Note comprise entre 13 et 14 si—en plus—le proxy FlopBox permet de gérer plusieurs serveurs FTP différents (ajout, suppression, modification des serveurs):**
......
......@@ -297,9 +297,9 @@ public class FTPResource {
ftp.setFileType(FTP.BINARY_FILE_TYPE);
if (extractZip != null && extractZip) {
if (!ftp.changeWorkingDirectory(path)) {
return Response.status(400).entity("Le chemin n'est pas un dossier").build();
}
// Créer le dossier cible et ses parents si nécessaire
createDirectories(ftp, path);
// Extraire le contenu du ZIP dans le dossier cible
ZipInputStream zis = new ZipInputStream(fileStream);
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
......@@ -316,6 +316,10 @@ public class FTPResource {
zis.close();
return Response.ok().build();
} else {
// Créer les répertoires parents si nécessaire
String parentDir = path.substring(0, path.lastIndexOf('/'));
createDirectories(ftp, parentDir);
// Upload du fichier
boolean success = ftp.storeFile(path, fileStream);
return success ? Response.ok().build() : Response.status(500).entity("Erreur d'upload").build();
}
......@@ -333,21 +337,6 @@ public class FTPResource {
}
}
private void createDirectories(FTPClient ftp, String path) throws IOException {
String[] dirs = path.split("/");
StringBuilder sb = new StringBuilder();
for (String dir : dirs) {
if (dir.isEmpty())
continue;
sb.append("/").append(dir);
String currentDir = sb.toString();
if (!ftp.changeWorkingDirectory(currentDir)) {
ftp.makeDirectory(currentDir);
ftp.changeWorkingDirectory(currentDir);
}
}
}
@POST
@Path("/{alias}/{path: .+}")
@Consumes({ MediaType.APPLICATION_OCTET_STREAM, MediaType.TEXT_PLAIN })
......@@ -392,6 +381,28 @@ public class FTPResource {
}
}
private void createDirectories(FTPClient ftp, String path) throws IOException {
String[] dirs = path.split("/");
StringBuilder sb = new StringBuilder();
for (String dir : dirs) {
if (dir.isEmpty())
continue;
if (sb.length() == 0) {
sb.append(dir);
} else {
sb.append("/").append(dir);
}
String currentDir = sb.toString();
if (!ftp.changeWorkingDirectory(currentDir)) {
if (ftp.makeDirectory(currentDir)) {
ftp.changeWorkingDirectory(currentDir);
} else {
throw new IOException("Échec de création du dossier: " + currentDir);
}
}
}
}
// delete the file or the content of a folder recursively
@DELETE
@Path("/{alias}/{path: .+}")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment