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
0a7f67c4
Commit
0a7f67c4
authored
1 month ago
by
fabiovandewaeter
Browse files
Options
Downloads
Patches
Plain Diff
save
parent
f003ec26
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/fil/sr2/flopbox/FTPResource.java
+0
-16
0 additions, 16 deletions
src/main/java/fil/sr2/flopbox/FTPResource.java
with
0 additions
and
16 deletions
src/main/java/fil/sr2/flopbox/FTPResource.java
+
0
−
16
View file @
0a7f67c4
...
...
@@ -42,7 +42,6 @@ public class FTPResource {
return
Response
.
status
(
Response
.
Status
.
NOT_FOUND
)
.
entity
(
"Serveur FTP non trouvé"
).
build
();
}
FTPClient
ftpClient
=
new
FTPClient
();
try
{
ftpClient
.
connect
(
config
.
getHost
(),
config
.
getPort
());
...
...
@@ -52,26 +51,21 @@ public class FTPResource {
}
ftpClient
.
enterLocalPassiveMode
();
ftpClient
.
setFileType
(
FTP
.
BINARY_FILE_TYPE
);
// Normaliser le chemin en retirant le slash final
if
(
path
.
endsWith
(
"/"
))
{
path
=
path
.
substring
(
0
,
path
.
length
()
-
1
);
}
// Vérifier si le chemin est un répertoire
FTPFile
[]
files
=
ftpClient
.
listFiles
(
path
);
if
(
files
==
null
||
files
.
length
==
0
)
{
return
Response
.
status
(
Response
.
Status
.
NOT_FOUND
)
.
entity
(
"Ressource non trouvée : "
+
path
).
build
();
}
// Construire la structure JSON
FtpNode
root
=
buildFtpTree
(
ftpClient
,
path
);
ftpClient
.
logout
();
ftpClient
.
disconnect
();
return
Response
.
ok
(
root
).
build
();
}
catch
(
IOException
e
)
{
return
Response
.
status
(
Response
.
Status
.
INTERNAL_SERVER_ERROR
)
.
entity
(
"Erreur FTP : "
+
e
.
getMessage
()).
build
();
...
...
@@ -82,7 +76,6 @@ public class FTPResource {
private
FtpNode
buildFtpTree
(
FTPClient
ftpClient
,
String
path
)
throws
IOException
{
FTPFile
[]
files
=
ftpClient
.
listFiles
(
path
);
FtpNode
node
=
new
FtpNode
(
getFileName
(
path
),
true
);
// Root est un dossier
if
(
files
!=
null
)
{
for
(
FTPFile
file
:
files
)
{
String
fullPath
=
path
+
"/"
+
file
.
getName
();
...
...
@@ -191,7 +184,6 @@ public class FTPResource {
FTPServerConfig
config
=
FTPServerRepository
.
getInstance
().
getServer
(
alias
);
ftp
.
connect
(
config
.
getHost
(),
config
.
getPort
());
ftp
.
login
(
user
,
pass
);
// Déterminer le type de ressource via le header
if
(
"directory"
.
equalsIgnoreCase
(
resourceType
))
{
boolean
dirCreated
=
ftp
.
makeDirectory
(
path
);
...
...
@@ -205,7 +197,6 @@ public class FTPResource {
?
Response
.
created
(
URI
.
create
(
path
)).
build
()
:
Response
.
status
(
400
).
entity
(
"Erreur création fichier"
).
build
();
}
}
catch
(
IOException
e
)
{
return
Response
.
serverError
().
entity
(
"Erreur FTP: "
+
e
.
getMessage
()).
build
();
}
finally
{
...
...
@@ -235,14 +226,11 @@ public class FTPResource {
FTPServerConfig
config
=
FTPServerRepository
.
getInstance
().
getServer
(
alias
);
ftp
.
connect
(
config
.
getHost
(),
config
.
getPort
());
ftp
.
login
(
user
,
pass
);
// Appel à la méthode récursive pour supprimer la ressource
boolean
deleted
=
deleteRecursive
(
ftp
,
path
);
return
deleted
?
Response
.
noContent
().
build
()
:
Response
.
status
(
Response
.
Status
.
NOT_FOUND
).
entity
(
"Ressource non trouvée"
).
build
();
}
catch
(
IOException
e
)
{
return
Response
.
serverError
().
entity
(
"Erreur FTP : "
+
e
.
getMessage
()).
build
();
}
finally
{
...
...
@@ -262,14 +250,12 @@ public class FTPResource {
if
(
ftp
.
deleteFile
(
path
))
{
return
true
;
}
// Si ce n'est pas un fichier, vérifie si c'est un répertoire
FTPFile
[]
files
=
ftp
.
listFiles
(
path
);
if
(
files
==
null
)
{
// Le chemin n'existe pas
return
false
;
}
// Supprime récursivement le contenu du répertoire
for
(
FTPFile
file
:
files
)
{
String
fullPath
=
path
+
"/"
+
file
.
getName
();
...
...
@@ -283,7 +269,6 @@ public class FTPResource {
}
}
}
// Supprime le répertoire lui-même
return
ftp
.
removeDirectory
(
path
);
}
...
...
@@ -304,7 +289,6 @@ public class FTPResource {
FTPServerConfig
config
=
FTPServerRepository
.
getInstance
().
getServer
(
alias
);
ftp
.
connect
(
config
.
getHost
(),
config
.
getPort
());
ftp
.
login
(
user
,
pass
);
System
.
out
.
print
(
oldPath
+
" "
+
newPath
);
boolean
success
=
ftp
.
rename
(
oldPath
,
newPath
);
return
success
...
...
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