Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FlopBox-Bouali
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hocine Bouali
FlopBox-Bouali
Commits
fd9c34cf
Commit
fd9c34cf
authored
4 years ago
by
Hocine Bouali
Browse files
Options
Downloads
Patches
Plain Diff
ajout des methodes pour agentFlopBox
parent
0e7334cd
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
pom.xml
+1
-0
1 addition, 0 deletions
pom.xml
src/main/java/fil/sr2/endpoints/ServiceFTPEndPoint.java
+74
-0
74 additions, 0 deletions
src/main/java/fil/sr2/endpoints/ServiceFTPEndPoint.java
src/main/java/fil/sr2/utils/Utils.java
+5
-1
5 additions, 1 deletion
src/main/java/fil/sr2/utils/Utils.java
with
80 additions
and
1 deletion
pom.xml
+
1
−
0
View file @
fd9c34cf
...
@@ -41,6 +41,7 @@
...
@@ -41,6 +41,7 @@
<groupId>
org.glassfish.jersey.media
</groupId>
<groupId>
org.glassfish.jersey.media
</groupId>
<artifactId>
jersey-media-multipart
</artifactId>
<artifactId>
jersey-media-multipart
</artifactId>
<version>
2.33
</version>
<version>
2.33
</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
junit
</groupId>
<groupId>
junit
</groupId>
...
...
This diff is collapsed.
Click to expand it.
src/main/java/fil/sr2/endpoints/ServiceFTPEndPoint.java
+
74
−
0
View file @
fd9c34cf
...
@@ -175,6 +175,44 @@ public class ServiceFTPEndPoint {
...
@@ -175,6 +175,44 @@ public class ServiceFTPEndPoint {
return
Response
.
ok
(
file
).
header
(
"Content-Disposition"
,
"attachment; filename=\""
+
filename
+
"\""
).
build
();
return
Response
.
ok
(
file
).
header
(
"Content-Disposition"
,
"attachment; filename=\""
+
filename
+
"\""
).
build
();
}
}
@GET
@Secured
@Path
(
"{alias}/file/last-modified/{path: .*}"
)
@Produces
(
MediaType
.
TEXT_PLAIN
)
public
Response
getLastDateFile
(
@PathParam
(
"alias"
)
String
alias
,
@PathParam
(
"path"
)
String
path
,
@DefaultValue
(
"anonymous"
)
@HeaderParam
(
"username"
)
String
username
,
@DefaultValue
(
"anonymous"
)
@HeaderParam
(
"password"
)
String
psw
,
@DefaultValue
(
"pasv"
)
@HeaderParam
(
"mode"
)
String
mode
,
@DefaultValue
(
"FTPS"
)
@HeaderParam
(
"type"
)
String
type
,
@DefaultValue
(
"21"
)
@HeaderParam
(
"port"
)
int
port
)
{
Response
r
=
init
(
alias
,
type
,
username
,
psw
,
mode
,
port
);
if
(!(
r
.
getStatus
()
==
Response
.
Status
.
ACCEPTED
.
getStatusCode
()))
{
// on verifie que l'init s'est bien passer
return
r
;
}
String
date
;
try
{
date
=
ftp
.
getModificationTime
(
path
);
if
(
date
==
null
)
{
return
Response
.
status
(
Response
.
Status
.
FORBIDDEN
)
.
entity
(
"file "
+
path
+
" not exist on the ftp server "
)
.
build
();
}
System
.
out
.
println
(
date
);
}
catch
(
IOException
e
)
{
return
Response
.
status
(
Response
.
Status
.
FORBIDDEN
)
.
entity
(
"file "
+
path
+
" not exist on the ftp server or you don't have the right to download it"
)
.
build
();
}
finally
{
try
{
ftp
.
disconnect
();
}
catch
(
IOException
e
)
{
}
}
return
Response
.
ok
(
date
).
build
();
}
/*
/*
* Méthode non fonctionnel qui permet de récuperer un dossier, de le zipper et
* Méthode non fonctionnel qui permet de récuperer un dossier, de le zipper et
* de l'envoyer au client
* de l'envoyer au client
...
@@ -353,6 +391,42 @@ public class ServiceFTPEndPoint {
...
@@ -353,6 +391,42 @@ public class ServiceFTPEndPoint {
return
Response
.
ok
(
"successfully renamed to "
+
rename
).
build
();
return
Response
.
ok
(
"successfully renamed to "
+
rename
).
build
();
}
}
@PUT
@Secured
@Path
(
"{alias}/relocate/{path: .*}"
)
@Produces
(
MediaType
.
TEXT_PLAIN
)
public
Response
relocate
(
@PathParam
(
"alias"
)
String
alias
,
@PathParam
(
"path"
)
String
path
,
@DefaultValue
(
"anonymous"
)
@HeaderParam
(
"username"
)
String
username
,
@DefaultValue
(
"anonymous"
)
@HeaderParam
(
"password"
)
String
psw
,
@DefaultValue
(
"pasv"
)
@HeaderParam
(
"mode"
)
String
mode
,
@DefaultValue
(
"FTP"
)
@HeaderParam
(
"type"
)
String
type
,
@QueryParam
(
"to"
)
String
rename
,
@DefaultValue
(
"21"
)
@HeaderParam
(
"port"
)
int
port
)
{
Response
r
=
init
(
alias
,
type
,
username
,
psw
,
mode
,
port
);
if
(!(
r
.
getStatus
()
==
Response
.
Status
.
ACCEPTED
.
getStatusCode
()))
{
// on verifie que l'init s'est bien passer
return
r
;
}
// if (path.endsWith("/")) {
// path = path.substring(0, path.length() - 1);
// }
try
{
if
(!
ftp
.
rename
(
path
,
rename
))
{
return
Response
.
status
(
Response
.
Status
.
BAD_REQUEST
).
build
();
}
}
catch
(
IOException
e
)
{
return
Response
.
status
(
Response
.
Status
.
FORBIDDEN
).
entity
(
"can't rename one file "
+
path
+
"!"
).
build
();
}
finally
{
try
{
ftp
.
disconnect
();
}
catch
(
IOException
e
)
{
}
}
return
Response
.
ok
(
"successfully renamed to "
+
rename
).
build
();
}
/**
/**
* Methode qui permet d'upload un fichier sur le serveur, pour envoyer un
* Methode qui permet d'upload un fichier sur le serveur, pour envoyer un
* dossier,il faut prealablement le zipper
* dossier,il faut prealablement le zipper
...
...
This diff is collapsed.
Click to expand it.
src/main/java/fil/sr2/utils/Utils.java
+
5
−
1
View file @
fd9c34cf
...
@@ -8,6 +8,7 @@ import java.io.FileOutputStream;
...
@@ -8,6 +8,7 @@ import java.io.FileOutputStream;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.io.OutputStream
;
import
java.io.PrintWriter
;
import
java.net.SocketException
;
import
java.net.SocketException
;
import
java.text.DateFormat
;
import
java.text.DateFormat
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
...
@@ -15,7 +16,7 @@ import java.util.Map;
...
@@ -15,7 +16,7 @@ import java.util.Map;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipOutputStream
;
import
java.util.zip.ZipOutputStream
;
import
org.apache.commons.net.PrintCommandListener
;
import
org.apache.commons.net.ftp.FTP
;
import
org.apache.commons.net.ftp.FTP
;
import
org.apache.commons.net.ftp.FTPClient
;
import
org.apache.commons.net.ftp.FTPClient
;
import
org.apache.commons.net.ftp.FTPFile
;
import
org.apache.commons.net.ftp.FTPFile
;
...
@@ -45,6 +46,8 @@ public class Utils {
...
@@ -45,6 +46,8 @@ public class Utils {
if
(
file
.
isDirectory
())
{
if
(
file
.
isDirectory
())
{
details
=
"["
+
details
+
"]"
;
details
=
"["
+
details
+
"]"
;
}
else
{
details
=
"<"
+
details
+
">"
;
}
}
details
+=
" "
+
file
.
getSize
();
details
+=
" "
+
file
.
getSize
();
details
+=
" "
+
file
.
getUser
();
details
+=
" "
+
file
.
getUser
();
...
@@ -180,6 +183,7 @@ public class Utils {
...
@@ -180,6 +183,7 @@ public class Utils {
f
.
login
(
username
,
psw
);
f
.
login
(
username
,
psw
);
f
.
sendCommand
(
"PBSZ 0"
);
f
.
sendCommand
(
"PBSZ 0"
);
f
.
sendCommand
(
"PROT P"
);
f
.
sendCommand
(
"PROT P"
);
f
.
addProtocolCommandListener
(
new
PrintCommandListener
(
new
PrintWriter
(
System
.
out
)));
if
(
mode
.
equals
(
"pasv"
))
{
if
(
mode
.
equals
(
"pasv"
))
{
f
.
enterLocalPassiveMode
();
f
.
enterLocalPassiveMode
();
}
else
if
(!
mode
.
equals
(
"port"
))
{
}
else
if
(!
mode
.
equals
(
"port"
))
{
...
...
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