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
35404a82
Commit
35404a82
authored
2 months ago
by
Fabio Vandewaeter
Browse files
Options
Downloads
Patches
Plain Diff
save
parent
913b9285
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
+13
-4
13 additions, 4 deletions
src/main/java/fil/sr2/flopbox/FTPResource.java
with
13 additions
and
4 deletions
src/main/java/fil/sr2/flopbox/FTPResource.java
+
13
−
4
View file @
35404a82
...
@@ -22,6 +22,7 @@ public class FTPResource {
...
@@ -22,6 +22,7 @@ public class FTPResource {
@GET
@GET
@Produces
(
MediaType
.
APPLICATION_JSON
)
@Produces
(
MediaType
.
APPLICATION_JSON
)
public
Response
listFTPServers
()
{
public
Response
listFTPServers
()
{
System
.
out
.
println
(
"listFTPServers()"
);
List
<
FTPServerConfig
>
servers
=
FTPServerRepository
.
getInstance
().
getAllServers
();
List
<
FTPServerConfig
>
servers
=
FTPServerRepository
.
getInstance
().
getAllServers
();
return
Response
.
ok
(
servers
).
build
();
return
Response
.
ok
(
servers
).
build
();
}
}
...
@@ -31,6 +32,7 @@ public class FTPResource {
...
@@ -31,6 +32,7 @@ public class FTPResource {
@Consumes
(
MediaType
.
APPLICATION_JSON
)
@Consumes
(
MediaType
.
APPLICATION_JSON
)
@Produces
(
MediaType
.
APPLICATION_JSON
)
@Produces
(
MediaType
.
APPLICATION_JSON
)
public
Response
addFTPServer
(
FTPServerConfig
config
,
@Context
UriInfo
uriInfo
)
{
public
Response
addFTPServer
(
FTPServerConfig
config
,
@Context
UriInfo
uriInfo
)
{
System
.
out
.
println
(
"addFTPServer()"
);
boolean
created
=
FTPServerRepository
.
getInstance
().
addServer
(
config
);
boolean
created
=
FTPServerRepository
.
getInstance
().
addServer
(
config
);
if
(!
created
)
{
if
(!
created
)
{
return
Response
.
status
(
Response
.
Status
.
CONFLICT
)
return
Response
.
status
(
Response
.
Status
.
CONFLICT
)
...
@@ -51,6 +53,7 @@ public class FTPResource {
...
@@ -51,6 +53,7 @@ public class FTPResource {
@PathParam
(
"path"
)
String
path
,
@PathParam
(
"path"
)
String
path
,
@HeaderParam
(
"X-FTP-User"
)
String
ftpUser
,
@HeaderParam
(
"X-FTP-User"
)
String
ftpUser
,
@HeaderParam
(
"X-FTP-Pass"
)
String
ftpPass
)
{
@HeaderParam
(
"X-FTP-Pass"
)
String
ftpPass
)
{
System
.
out
.
println
(
"getFTPContent()"
);
FTPServerConfig
config
=
FTPServerRepository
.
getInstance
().
getServer
(
alias
);
FTPServerConfig
config
=
FTPServerRepository
.
getInstance
().
getServer
(
alias
);
if
(
config
==
null
)
{
if
(
config
==
null
)
{
return
Response
.
status
(
Response
.
Status
.
NOT_FOUND
)
return
Response
.
status
(
Response
.
Status
.
NOT_FOUND
)
...
@@ -80,6 +83,7 @@ public class FTPResource {
...
@@ -80,6 +83,7 @@ public class FTPResource {
@DELETE
@DELETE
@Path
(
"/{alias}"
)
@Path
(
"/{alias}"
)
public
Response
removeFTPServer
(
@PathParam
(
"alias"
)
String
alias
)
{
public
Response
removeFTPServer
(
@PathParam
(
"alias"
)
String
alias
)
{
System
.
out
.
println
(
"removeFTPServer()"
);
boolean
removed
=
FTPServerRepository
.
getInstance
().
removeServer
(
alias
);
boolean
removed
=
FTPServerRepository
.
getInstance
().
removeServer
(
alias
);
return
removed
?
Response
.
noContent
().
build
()
:
Response
.
status
(
Response
.
Status
.
NOT_FOUND
).
build
();
return
removed
?
Response
.
noContent
().
build
()
:
Response
.
status
(
Response
.
Status
.
NOT_FOUND
).
build
();
}
}
...
@@ -88,12 +92,13 @@ public class FTPResource {
...
@@ -88,12 +92,13 @@ public class FTPResource {
@Path
(
"/{alias}"
)
@Path
(
"/{alias}"
)
@Consumes
(
MediaType
.
APPLICATION_JSON
)
@Consumes
(
MediaType
.
APPLICATION_JSON
)
public
Response
updateFTPServer
(
@PathParam
(
"alias"
)
String
alias
,
FTPServerConfig
newConfig
)
{
public
Response
updateFTPServer
(
@PathParam
(
"alias"
)
String
alias
,
FTPServerConfig
newConfig
)
{
System
.
out
.
println
(
"updateFTPServer()"
);
boolean
updated
=
FTPServerRepository
.
getInstance
().
updateServer
(
alias
,
newConfig
);
boolean
updated
=
FTPServerRepository
.
getInstance
().
updateServer
(
alias
,
newConfig
);
return
updated
?
Response
.
ok
(
newConfig
).
build
()
:
Response
.
status
(
Response
.
Status
.
NOT_FOUND
).
build
();
return
updated
?
Response
.
ok
(
newConfig
).
build
()
:
Response
.
status
(
Response
.
Status
.
NOT_FOUND
).
build
();
}
}
@GET
@GET
@Path
(
"/{alias}/{path: .+}
/download
"
)
@Path
(
"/{alias}/{path: .+}"
)
@Produces
(
MediaType
.
APPLICATION_OCTET_STREAM
)
@Produces
(
MediaType
.
APPLICATION_OCTET_STREAM
)
public
Response
downloadFile
(
public
Response
downloadFile
(
@PathParam
(
"alias"
)
String
alias
,
@PathParam
(
"alias"
)
String
alias
,
...
@@ -101,6 +106,7 @@ public class FTPResource {
...
@@ -101,6 +106,7 @@ public class FTPResource {
@HeaderParam
(
"X-FTP-User"
)
String
user
,
@HeaderParam
(
"X-FTP-User"
)
String
user
,
@HeaderParam
(
"X-FTP-Pass"
)
String
pass
)
{
@HeaderParam
(
"X-FTP-Pass"
)
String
pass
)
{
System
.
out
.
println
(
"downloadFile()"
);
FTPServerConfig
config
=
FTPServerRepository
.
getInstance
().
getServer
(
alias
);
FTPServerConfig
config
=
FTPServerRepository
.
getInstance
().
getServer
(
alias
);
if
(
config
==
null
)
{
if
(
config
==
null
)
{
return
Response
.
status
(
Response
.
Status
.
NOT_FOUND
)
return
Response
.
status
(
Response
.
Status
.
NOT_FOUND
)
...
@@ -175,7 +181,7 @@ public class FTPResource {
...
@@ -175,7 +181,7 @@ public class FTPResource {
}
}
@PUT
@PUT
@Path
(
"/{alias}/{path: .+}
/upload
"
)
@Path
(
"/{alias}/{path: .+}"
)
@Consumes
(
MediaType
.
APPLICATION_OCTET_STREAM
)
@Consumes
(
MediaType
.
APPLICATION_OCTET_STREAM
)
public
Response
uploadFile
(
public
Response
uploadFile
(
@PathParam
(
"alias"
)
String
alias
,
@PathParam
(
"alias"
)
String
alias
,
...
@@ -184,6 +190,7 @@ public class FTPResource {
...
@@ -184,6 +190,7 @@ public class FTPResource {
@HeaderParam
(
"X-FTP-Pass"
)
String
pass
,
@HeaderParam
(
"X-FTP-Pass"
)
String
pass
,
InputStream
fileStream
)
{
InputStream
fileStream
)
{
System
.
out
.
println
(
"uploadFile()"
);
FTPServerConfig
config
=
FTPServerRepository
.
getInstance
().
getServer
(
alias
);
FTPServerConfig
config
=
FTPServerRepository
.
getInstance
().
getServer
(
alias
);
FTPClient
ftp
=
new
FTPClient
();
FTPClient
ftp
=
new
FTPClient
();
try
{
try
{
...
@@ -206,13 +213,14 @@ public class FTPResource {
...
@@ -206,13 +213,14 @@ public class FTPResource {
}
}
@POST
@POST
@Path
(
"/{alias}/{path: .+}
/mkdir
"
)
@Path
(
"/{alias}/{path: .+}"
)
public
Response
createDirectory
(
public
Response
createDirectory
(
@PathParam
(
"alias"
)
String
alias
,
@PathParam
(
"alias"
)
String
alias
,
@PathParam
(
"path"
)
String
path
,
@PathParam
(
"path"
)
String
path
,
@HeaderParam
(
"X-FTP-User"
)
String
user
,
@HeaderParam
(
"X-FTP-User"
)
String
user
,
@HeaderParam
(
"X-FTP-Pass"
)
String
pass
)
throws
SocketException
,
IOException
{
@HeaderParam
(
"X-FTP-Pass"
)
String
pass
)
throws
SocketException
,
IOException
{
System
.
out
.
println
(
"createFirectory()"
);
FTPClient
ftp
=
new
FTPClient
();
FTPClient
ftp
=
new
FTPClient
();
try
{
try
{
FTPServerConfig
config
=
FTPServerRepository
.
getInstance
().
getServer
(
alias
);
FTPServerConfig
config
=
FTPServerRepository
.
getInstance
().
getServer
(
alias
);
...
@@ -233,13 +241,14 @@ public class FTPResource {
...
@@ -233,13 +241,14 @@ public class FTPResource {
}
}
@DELETE
@DELETE
@Path
(
"/{alias}/{path: .+}
/rmdir
"
)
@Path
(
"/{alias}/{path: .+}"
)
public
Response
deleteDirectory
(
public
Response
deleteDirectory
(
@PathParam
(
"alias"
)
String
alias
,
@PathParam
(
"alias"
)
String
alias
,
@PathParam
(
"path"
)
String
path
,
@PathParam
(
"path"
)
String
path
,
@HeaderParam
(
"X-FTP-User"
)
String
user
,
@HeaderParam
(
"X-FTP-User"
)
String
user
,
@HeaderParam
(
"X-FTP-Pass"
)
String
pass
)
throws
SocketException
,
IOException
{
@HeaderParam
(
"X-FTP-Pass"
)
String
pass
)
throws
SocketException
,
IOException
{
System
.
out
.
println
(
"deleteDirectory()"
);
FTPClient
ftp
=
new
FTPClient
();
FTPClient
ftp
=
new
FTPClient
();
try
{
try
{
FTPServerConfig
config
=
FTPServerRepository
.
getInstance
().
getServer
(
alias
);
FTPServerConfig
config
=
FTPServerRepository
.
getInstance
().
getServer
(
alias
);
...
...
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