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
f4bae7d1
Commit
f4bae7d1
authored
2 months ago
by
Fabio Vandewaeter
Browse files
Options
Downloads
Patches
Plain Diff
creation fichier ou dossier
parent
c64eb3a7
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
+56
-5
56 additions, 5 deletions
src/main/java/fil/sr2/flopbox/FTPResource.java
with
56 additions
and
5 deletions
src/main/java/fil/sr2/flopbox/FTPResource.java
+
56
−
5
View file @
f4bae7d1
...
...
@@ -174,22 +174,73 @@ public class FTPResource {
}
}
/*
* @POST
*
* @Path("/{alias}/{path: .+}")
* public Response createDirectory(
*
* @PathParam("alias") String alias,
*
* @PathParam("path") String path,
*
* @HeaderParam("X-FTP-User") String user,
*
* @HeaderParam("X-FTP-Pass") String pass) throws SocketException, IOException {
*
* System.out.println("createFirectory()");
* FTPClient ftp = new FTPClient();
* try {
* FTPServerConfig config = FTPServerRepository.getInstance().getServer(alias);
* ftp.connect(config.getHost(), config.getPort());
* ftp.login(user, pass);
* return ftp.makeDirectory(path) ? Response.created(URI.create(path)).build()
* : Response.status(Response.Status.BAD_REQUEST).build();
* } finally {
* try {
* if (ftp.isConnected()) {
* ftp.logout();
* ftp.disconnect();
* }
* } catch (IOException e) {
* e.printStackTrace();
* }
* }
* }
*/
@POST
@Path
(
"/{alias}/{path: .+}"
)
public
Response
createDirectory
(
@Consumes
({
MediaType
.
APPLICATION_OCTET_STREAM
,
MediaType
.
TEXT_PLAIN
})
// Accepter les fichiers
public
Response
createResource
(
@PathParam
(
"alias"
)
String
alias
,
@PathParam
(
"path"
)
String
path
,
@HeaderParam
(
"X-FTP-User"
)
String
user
,
@HeaderParam
(
"X-FTP-Pass"
)
String
pass
)
throws
SocketException
,
IOException
{
@HeaderParam
(
"X-FTP-Pass"
)
String
pass
,
InputStream
inputStream
)
{
// Contenu optionnel
System
.
out
.
println
(
"createFirectory()"
);
FTPClient
ftp
=
new
FTPClient
();
try
{
FTPServerConfig
config
=
FTPServerRepository
.
getInstance
().
getServer
(
alias
);
ftp
.
connect
(
config
.
getHost
(),
config
.
getPort
());
ftp
.
login
(
user
,
pass
);
return
ftp
.
makeDirectory
(
path
)
?
Response
.
created
(
URI
.
create
(
path
)).
build
()
:
Response
.
status
(
Response
.
Status
.
BAD_REQUEST
).
build
();
// Si le flux est vide (0 octet), créer un répertoire
if
(
inputStream
.
available
()
==
0
)
{
boolean
dirCreated
=
ftp
.
makeDirectory
(
path
);
return
dirCreated
?
Response
.
created
(
URI
.
create
(
path
)).
build
()
:
Response
.
status
(
400
).
entity
(
"Erreur création répertoire"
).
build
();
}
// Sinon, créer un fichier
else
{
boolean
fileCreated
=
ftp
.
storeFile
(
path
,
inputStream
);
return
fileCreated
?
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
{
try
{
if
(
ftp
.
isConnected
())
{
...
...
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