Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SR2-projet1-VANDEWAETER
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Fabio Vandewaeter
SR2-projet1-VANDEWAETER
Commits
f557b7ed
Commit
f557b7ed
authored
2 months ago
by
fabiovandewaeter
Browse files
Options
Downloads
Patches
Plain Diff
upload dossier
parent
f21341e6
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+2
-2
2 additions, 2 deletions
README.md
src/main/java/fil/sr2/flopbox/FTPResource.java
+1
-1
1 addition, 1 deletion
src/main/java/fil/sr2/flopbox/FTPResource.java
src/main/java/fil/sr2/flopbox/FTPService.java
+21
-12
21 additions, 12 deletions
src/main/java/fil/sr2/flopbox/FTPService.java
with
24 additions
and
15 deletions
README.md
+
2
−
2
View file @
f557b7ed
...
@@ -158,12 +158,12 @@ curl -X POST -H "X-Resource-Type: folder" -H "Authorization: Bearer valid-token-
...
@@ -158,12 +158,12 @@ curl -X POST -H "X-Resource-Type: folder" -H "Authorization: Bearer valid-token-
-
créer fichier :
-
créer fichier :
```
shell
```
shell
curl
-X
POST
-H
"X-Resource-Type: file"
-H
"Authorization: Bearer valid-token-1"
-H
"X-FTP-User: user"
-H
"X-FTP-Pass: password"
http://localhost:8080/ftps/mon-ftp/
dossier/
fichier
curl
-X
POST
-H
"X-Resource-Type: file"
-H
"Authorization: Bearer valid-token-1"
-H
"X-FTP-User: user"
-H
"X-FTP-Pass: password"
http://localhost:8080/ftps/mon-ftp/fichier
```
```
-
renommer :
-
renommer :
```
shell
```
shell
curl
-X
PUT
-H
"Authorization: Bearer valid-token-1"
-H
"X-FTP-User: user"
-H
"X-FTP-Pass: password"
-H
"Content-Type: text/plain"
-d
"nouveau_nom"
http://localhost:8080/ftps/mon-ftp/
dossier/rename
curl
-X
PUT
-H
"Authorization: Bearer valid-token-1"
-H
"X-FTP-User: user"
-H
"X-FTP-Pass: password"
-H
"Content-Type: text/plain"
-d
"nouveau_nom"
http://localhost:8080/ftps/mon-ftp/
rename/fichier
```
```
-
supprimer dossier/fichier :
-
supprimer dossier/fichier :
...
...
This diff is collapsed.
Click to expand it.
src/main/java/fil/sr2/flopbox/FTPResource.java
+
1
−
1
View file @
f557b7ed
...
@@ -225,7 +225,7 @@ public class FTPResource {
...
@@ -225,7 +225,7 @@ public class FTPResource {
}
}
@PUT
@PUT
@Path
(
"/{alias}/{path: .+}
/rename
"
)
@Path
(
"/{alias}/
rename/
{path: .+}"
)
@Consumes
(
MediaType
.
TEXT_PLAIN
)
@Consumes
(
MediaType
.
TEXT_PLAIN
)
public
Response
renameResource
(
public
Response
renameResource
(
@PathParam
(
"alias"
)
String
alias
,
@PathParam
(
"alias"
)
String
alias
,
...
...
This diff is collapsed.
Click to expand it.
src/main/java/fil/sr2/flopbox/FTPService.java
+
21
−
12
View file @
f557b7ed
...
@@ -279,9 +279,11 @@ public class FTPService {
...
@@ -279,9 +279,11 @@ public class FTPService {
while
((
entry
=
zis
.
getNextEntry
())
!=
null
)
{
while
((
entry
=
zis
.
getNextEntry
())
!=
null
)
{
String
entryName
=
entry
.
getName
();
String
entryName
=
entry
.
getName
();
String
fullPath
=
constructPath
(
targetPath
,
entryName
);
String
fullPath
=
constructPath
(
targetPath
,
entryName
);
System
.
out
.
println
(
"[DEBUG] Traitement entrée: "
+
entry
.
getName
()
if
(
fullPath
==
null
)
{
+
" → "
+
fullPath
);
zis
.
closeEntry
();
continue
;
// Ignorer l'entrée racine
}
System
.
out
.
println
(
"[DEBUG] Traitement entrée: "
+
entry
.
getName
()
+
" → "
+
fullPath
);
if
(
entry
.
isDirectory
())
{
if
(
entry
.
isDirectory
())
{
createDirectories
(
ftp
,
fullPath
);
createDirectories
(
ftp
,
fullPath
);
}
else
{
}
else
{
...
@@ -300,11 +302,20 @@ public class FTPService {
...
@@ -300,11 +302,20 @@ public class FTPService {
private
String
constructPath
(
String
basePath
,
String
entryPath
)
{
private
String
constructPath
(
String
basePath
,
String
entryPath
)
{
// Ignorer le premier segment du chemin (dossier racine du ZIP)
// Ignorer le premier segment du chemin (dossier racine du ZIP)
String
[]
parts
=
entryPath
.
split
(
"/"
);
String
[]
parts
=
entryPath
.
split
(
"/"
);
if
(
parts
.
length
>
1
)
{
List
<
String
>
partsList
=
new
ArrayList
<>();
String
normalizedEntry
=
String
.
join
(
"/"
,
Arrays
.
copyOfRange
(
parts
,
1
,
parts
.
length
));
for
(
String
part
:
parts
)
{
return
basePath
.
isEmpty
()
?
normalizedEntry
:
basePath
+
"/"
+
normalizedEntry
;
if
(!
part
.
isEmpty
())
{
partsList
.
add
(
part
);
}
}
}
return
entryPath
;
// Cas où l'entrée est déjà à la racine
if
(!
partsList
.
isEmpty
())
{
partsList
.
remove
(
0
);
// Retirer le premier segment (racine du ZIP)
}
String
normalizedEntry
=
String
.
join
(
"/"
,
partsList
);
if
(
normalizedEntry
.
isEmpty
())
{
return
null
;
// Indique une entrée de répertoire racine à ignorer
}
return
basePath
.
isEmpty
()
?
normalizedEntry
:
basePath
+
"/"
+
normalizedEntry
;
}
}
private
void
createParentDirectories
(
FTPClient
ftp
,
String
filePath
)
throws
IOException
{
private
void
createParentDirectories
(
FTPClient
ftp
,
String
filePath
)
throws
IOException
{
...
@@ -342,12 +353,10 @@ public class FTPService {
...
@@ -342,12 +353,10 @@ public class FTPService {
private
void
uploadFileEntry
(
FTPClient
ftp
,
String
path
,
InputStream
is
)
private
void
uploadFileEntry
(
FTPClient
ftp
,
String
path
,
InputStream
is
)
throws
IOException
,
FTPException
{
throws
IOException
,
FTPException
{
// Supprimer URLDecoder.decode() !
String
fileName
=
path
.
contains
(
"/"
)
?
path
.
substring
(
path
.
lastIndexOf
(
'/'
)
+
1
)
:
path
;
String
decodedPath
=
path
;
try
(
InputStream
bais
=
is
)
{
try
(
InputStream
bais
=
is
)
{
if
(!
ftp
.
storeFile
(
decodedPath
,
bais
))
{
if
(!
ftp
.
storeFile
(
fileName
,
bais
))
{
throw
new
FTPException
(
"Échec upload: "
+
decodedP
ath
,
500
);
throw
new
FTPException
(
"Échec upload: "
+
p
ath
,
500
);
}
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment