From 482bbe71ef60d4dd46404b051f433e8c9a673d45 Mon Sep 17 00:00:00 2001
From: Vandewaeter Fabio <fabio.vandewaeter.etu@univ-lille.fr>
Date: Mon, 10 Mar 2025 11:16:41 +0100
Subject: [PATCH] save

---
 README.md                                      | 8 ++++++++
 src/main/java/fil/sr2/flopbox/FTPResource.java | 5 +++++
 2 files changed, 13 insertions(+)

diff --git a/README.md b/README.md
index 8065859..87b1645 100644
--- a/README.md
+++ b/README.md
@@ -37,6 +37,14 @@ Pour exécuter uniquement les tests il faut lancer la commande suivante :
 mvn test
 ```
 
+```
+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
+
+curl -H "Authorization: Bearer valid-token-1" http://localhost:8080/ftps -v
+
+curl -H "Authorization: Bearer valid-token-1" -o fichier.html http://localhost:8080/ftps/mon-ftp/test/download -v
+```
+
 ## Détails du code
 ### Générer la javadoc
 Lancer la commande suivante :
diff --git a/src/main/java/fil/sr2/flopbox/FTPResource.java b/src/main/java/fil/sr2/flopbox/FTPResource.java
index 521c491..7e199da 100644
--- a/src/main/java/fil/sr2/flopbox/FTPResource.java
+++ b/src/main/java/fil/sr2/flopbox/FTPResource.java
@@ -102,7 +102,12 @@ public class FTPResource {
         try {
             ftp.connect(config.getHost(), config.getPort());
             ftp.login(user, pass);
+            // path = "/home/m1gl/fabio.vandewaeter.etu/M1/SR2/serveur-ftp-test/" + path;
             InputStream is = ftp.retrieveFileStream(path);
+            if (is == null) {
+                return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
+                        .entity("Could not retrieve file : " + path).build();
+            }
             return Response.ok(is)
                     .header("Content-Disposition", "attachment; filename=\"" + getFileName(path) + "\"")
                     .build();
-- 
GitLab