Skip to content
Snippets Groups Projects
Commit 82ac8812 authored by Matthias Severin's avatar Matthias Severin
Browse files

ajout de la documentation et du readme

parent e78c38c5
No related branches found
No related tags found
No related merge requests found
# Tree FTP - Matthias SEVERIN # Tree FTP - Matthias SEVERIN
Connexion au FTP réussie. ## Generation de la javadoc
\ No newline at end of file
mvn javadoc:javadoc
## Generation du fichier jar
mvn package
## Execution avec 1 parametre
java -jar target\TREE_FTP-1.0-SNAPSHOT.jar [IP du serveur]
Permet de lancer la methode tree sur le serveur passe en parametre
Exemple : java -jar target\TREE_FTP-1.0-SNAPSHOT.jar ftp.ubuntu.com
## Execution avec 2 parametres
java -jar target\TREE_FTP-1.0-SNAPSHOT.jar [IP du serveur] [profondeur]
Permet de lancer la methode tree sur le serveur passe en parametre avec une profondeur maximale
Exemple : java -jar target\TREE_FTP-1.0-SNAPSHOT.jar ftp.ubuntu.com 3
## Execution avec 4 parametres
java -jar target\TREE_FTP-1.0-SNAPSHOT.jar [IP du serveur] [profondeur] [username] [password]
Permet de lancer la methode tree sur le serveur passe en parametre en se connectant avec son nom d'utilisateur et son mot de passe
Exemple sans profondeur maximale : java -jar target\TREE_FTP-1.0-SNAPSHOT.jar ftp.ubuntu.com -1 toto titi
Exemple avec profondeur maximale : java -jar target\TREE_FTP-1.0-SNAPSHOT.jar ftp.ubuntu.com 2 toto titi
...@@ -76,6 +76,16 @@ ...@@ -76,6 +76,16 @@
<artifactId>maven-project-info-reports-plugin</artifactId> <artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version> <version>3.0.0</version>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version>
<configuration>
<reportOutputDirectory>${project.build.directory}/docs</reportOutputDirectory>
<destDir>docs</destDir>
<nohelp>true</nohelp>
</configuration>
</plugin>
</plugins> </plugins>
</pluginManagement> </pluginManagement>
</build> </build>
......
package fil.sr1.TREE_FTP; package fil.sr1.TREE_FTP;
/**
* Classe qui decrit les documents
* @author Matthias Severin
*/
public class Document { public class Document {
protected String name; protected String name;
protected DocumentType type; protected DocumentType type;
protected boolean executable; protected boolean executable;
/**
* @param name le nom du fichier
* @param type le type du fichier
* @param executable un boolean qui montre si le fichier est executable ou non
*/
public Document(String name, DocumentType type, boolean executable) { public Document(String name, DocumentType type, boolean executable) {
this.name = name; this.name = name;
this.type = type; this.type = type;
this.executable = executable; this.executable = executable;
} }
/**
* @param data les informations d'un fichier
* @return genere le Document qui correspond a data
*/
public static Document getDocumentFromData(String data) { public static Document getDocumentFromData(String data) {
DocumentType type; DocumentType type;
switch (data.charAt(0)) { switch (data.charAt(0)) {
......
package fil.sr1.TREE_FTP; package fil.sr1.TREE_FTP;
/**
* Enumeration des differents type de document possible
* @author Matthias Severin
*/
public enum DocumentType { public enum DocumentType {
FILE, DIRECTORY, LINK; FILE, DIRECTORY, LINK;
} }
...@@ -9,6 +9,10 @@ import java.io.PrintWriter; ...@@ -9,6 +9,10 @@ import java.io.PrintWriter;
import java.net.Socket; import java.net.Socket;
import java.util.ArrayList; import java.util.ArrayList;
/**
* Classe qui s'occupe de la gestion des serveurs FTP
* @author Matthias Severin
*/
public class FTP { public class FTP {
private Socket socket; private Socket socket;
...@@ -16,6 +20,11 @@ public class FTP { ...@@ -16,6 +20,11 @@ public class FTP {
private BufferedReader reader; private BufferedReader reader;
private boolean debug; private boolean debug;
/**
* @param ip l'ip du serveur
* @param port le port sur lequel il faut se connecter
* @param debug si debug est a true les messages envoyes par le serveur seront affiches, sinon ils ne le seront pas
*/
public FTP(String ip, int port, boolean debug) { public FTP(String ip, int port, boolean debug) {
this.debug = debug; this.debug = debug;
try { try {
...@@ -32,10 +41,18 @@ public class FTP { ...@@ -32,10 +41,18 @@ public class FTP {
} }
} }
/**
* Envoi la commande command au serveur FTP
* @param command une commande FTP
*/
public void write(String command) { public void write(String command) {
printer.println(command); printer.println(command);
} }
/**
* Recupere un message envoye par le serveur
* @return le message recu
*/
public String readLine() { public String readLine() {
try { try {
String res = reader.readLine(); String res = reader.readLine();
...@@ -49,10 +66,18 @@ public class FTP { ...@@ -49,10 +66,18 @@ public class FTP {
} }
} }
/**
* Cree la connexion avec le serveur FTP en mode anonyme
*/
public void connect() { public void connect() {
connect("anonymous", "anonymous"); connect("anonymous", "anonymous");
} }
/**
* Cree la connexion avec le serveur FTP
* @param username le nom de l'utilisateur
* @param password le mot de passe
*/
public void connect(String username, String password) { public void connect(String username, String password) {
readLine(); readLine();
...@@ -75,6 +100,9 @@ public class FTP { ...@@ -75,6 +100,9 @@ public class FTP {
readLine(); readLine();
} }
/**
* Ferme la connexion avec le serveur
*/
public void close() { public void close() {
try { try {
socket.close(); socket.close();
...@@ -83,6 +111,11 @@ public class FTP { ...@@ -83,6 +111,11 @@ public class FTP {
} }
} }
/**
* Parse le message data pour retourner l'ip du nouveau socket
* @param data le message recu par le serveur qui donne les informations de l'ip/port d'un nouveau socket
* @return l'adresse ip du nouveau socket
*/
public static String getIpFromData(String data) { public static String getIpFromData(String data) {
String dataArray[] = data.substring(data.indexOf('(') + 1, data.indexOf(')')).split(","); String dataArray[] = data.substring(data.indexOf('(') + 1, data.indexOf(')')).split(",");
String ip = dataArray[0]; String ip = dataArray[0];
...@@ -92,12 +125,20 @@ public class FTP { ...@@ -92,12 +125,20 @@ public class FTP {
return ip; return ip;
} }
/**
* Parse le message data pour retourner le port du nouveau socket
* @param data le message recu par le serveur qui donne les informations de l'ip/port d'un nouveau socket
* @return le port du nouveau socket
*/
public static int getPortFromData(String data) { public static int getPortFromData(String data) {
String dataArray[] = data.substring(data.indexOf('(') + 1, data.indexOf(')')).split(","); String dataArray[] = data.substring(data.indexOf('(') + 1, data.indexOf(')')).split(",");
int port = (Integer.parseInt(dataArray[4]) * 256) + Integer.parseInt(dataArray[5]); int port = (Integer.parseInt(dataArray[4]) * 256) + Integer.parseInt(dataArray[5]);
return port; return port;
} }
/** Envoi la commande PASV au serveur FTP et se connecte au nouveau socket
* @return la connexion au nouveau socket
*/
public FTP pasv() { public FTP pasv() {
write("PASV"); write("PASV");
String result = readLine(); String result = readLine();
...@@ -106,6 +147,12 @@ public class FTP { ...@@ -106,6 +147,12 @@ public class FTP {
return new FTP(ip, port, false); return new FTP(ip, port, false);
} }
/**
* Liste le contenu du repertoire actuel et ferme la connexion a receiver
* @param receiver une connexion FTP qui permet de recevoir des informations demandees par le
* serveur FTP principal (obtenu via la commande pasv)
* @return la liste des documents contenus dans le repertoire actuelle
*/
public ArrayList<Document> list(FTP receiver) { public ArrayList<Document> list(FTP receiver) {
ArrayList<Document> content = new ArrayList<>(); ArrayList<Document> content = new ArrayList<>();
write("LIST"); write("LIST");
...@@ -120,6 +167,9 @@ public class FTP { ...@@ -120,6 +167,9 @@ public class FTP {
return content; return content;
} }
/**
* Affiche le contenu du repertoire actuel en combinant les commandes pasv et list
*/
public void listCurrentDirectory() { public void listCurrentDirectory() {
FTP receiver = pasv(); FTP receiver = pasv();
ArrayList<Document> content = list(receiver); ArrayList<Document> content = list(receiver);
...@@ -128,16 +178,27 @@ public class FTP { ...@@ -128,16 +178,27 @@ public class FTP {
} }
} }
/** Se deplace dans le repertoire directory
* @param directory un repertoire
*/
public void cwd(String directory) { public void cwd(String directory) {
write("CWD " + directory); write("CWD " + directory);
readLine(); readLine();
} }
/**
* Retourne dans le repertoire parent
*/
public void cdup() { public void cdup() {
write("CDUP"); write("CDUP");
readLine(); readLine();
} }
/**
* Affiche l'arborescense du repertoire actuel
* @param indent permet de definir l'indentation initiale
* @param depth profondeur maximale
*/
private void tree(int indent, int depth) { private void tree(int indent, int depth) {
FTP receiver = pasv(); FTP receiver = pasv();
ArrayList<Document> content = list(receiver); ArrayList<Document> content = list(receiver);
...@@ -158,10 +219,17 @@ public class FTP { ...@@ -158,10 +219,17 @@ public class FTP {
} }
} }
/**
* Affiche l'arborescense du repertoire actuel sans profondeur maximale
*/
public void tree() { public void tree() {
tree(0, -1); tree(0, -1);
} }
/**
* Affiche l'arborescense du repertoire actuel avec une profondeur maximale
* @param depth la profondeur maximale
*/
public void tree(int depth) { public void tree(int depth) {
tree(0, depth); tree(0, depth);
} }
......
package fil.sr1.TREE_FTP; package fil.sr1.TREE_FTP;
/**
* Classe principal du projet de SR1 : TREE FTP
* @author Matthias Severin
*/
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
...@@ -7,9 +11,6 @@ public class Main { ...@@ -7,9 +11,6 @@ public class Main {
if (args.length > 0) { if (args.length > 0) {
ftp = new FTP(args[0], 21, false); ftp = new FTP(args[0], 21, false);
} else {
ftp = new FTP("ftp.ubuntu.com", 21, false);
}
if (args.length > 3) { if (args.length > 3) {
ftp.connect(args[2], args[3]); ftp.connect(args[2], args[3]);
...@@ -24,5 +25,9 @@ public class Main { ...@@ -24,5 +25,9 @@ public class Main {
} }
ftp.close(); ftp.close();
} else {
System.out.println("You need at least 1 argument");
}
} }
} }
...@@ -4,8 +4,15 @@ import static org.junit.Assert.assertTrue; ...@@ -4,8 +4,15 @@ import static org.junit.Assert.assertTrue;
import org.junit.Test; import org.junit.Test;
/**
* Tests de la classe Document
* @author Matthias Severin
*/
public class DocumentTest { public class DocumentTest {
/**
* Test de la generation d'un fichier executable
*/
@Test @Test
public void testGetDocumentFromFileExecutable() { public void testGetDocumentFromFileExecutable() {
String data = "-rwxr-xr-x 31 997 997 4096 Feb 01 13:47 file"; String data = "-rwxr-xr-x 31 997 997 4096 Feb 01 13:47 file";
...@@ -15,6 +22,9 @@ public class DocumentTest { ...@@ -15,6 +22,9 @@ public class DocumentTest {
assertTrue(file.executable); assertTrue(file.executable);
} }
/**
* Test de la generation d'un fichier non executable
*/
@Test @Test
public void testGetDocumentFromFileNotExecutable() { public void testGetDocumentFromFileNotExecutable() {
String data = "-rwxr-xr-- 31 997 997 4096 Feb 01 13:47 file"; String data = "-rwxr-xr-- 31 997 997 4096 Feb 01 13:47 file";
...@@ -24,6 +34,9 @@ public class DocumentTest { ...@@ -24,6 +34,9 @@ public class DocumentTest {
assertTrue(! file.executable); assertTrue(! file.executable);
} }
/**
* Test de la generation d'un dossier executable
*/
@Test @Test
public void testGetDocumentFromDirectoryExecutable() { public void testGetDocumentFromDirectoryExecutable() {
String data = "drwxr-xr-x 31 997 997 4096 Feb 01 13:47 directory"; String data = "drwxr-xr-x 31 997 997 4096 Feb 01 13:47 directory";
...@@ -33,6 +46,9 @@ public class DocumentTest { ...@@ -33,6 +46,9 @@ public class DocumentTest {
assertTrue(file.executable); assertTrue(file.executable);
} }
/**
* Test de la generation d'un dossier non executable
*/
@Test @Test
public void testGetDocumentFromDirectoryNotExecutable() { public void testGetDocumentFromDirectoryNotExecutable() {
String data = "drwxr-xr-- 31 997 997 4096 Feb 01 13:47 directory"; String data = "drwxr-xr-- 31 997 997 4096 Feb 01 13:47 directory";
...@@ -42,6 +58,9 @@ public class DocumentTest { ...@@ -42,6 +58,9 @@ public class DocumentTest {
assertTrue(! directory.executable); assertTrue(! directory.executable);
} }
/**
* Test de la generation d'un lien executable
*/
@Test @Test
public void testGetDocumentFromLinkExecutable() { public void testGetDocumentFromLinkExecutable() {
String data = "lrwxr-xr-x 31 997 997 4096 Feb 01 13:47 linkTo -> this"; String data = "lrwxr-xr-x 31 997 997 4096 Feb 01 13:47 linkTo -> this";
...@@ -51,6 +70,9 @@ public class DocumentTest { ...@@ -51,6 +70,9 @@ public class DocumentTest {
assertTrue(link.executable); assertTrue(link.executable);
} }
/**
* Test de la generation d'un lien non executables
*/
@Test @Test
public void testGetDocumentFromLinkNotExecutable() { public void testGetDocumentFromLinkNotExecutable() {
String data = "lrwxr-xr-- 31 997 997 4096 Feb 01 13:47 linkTo -> this"; String data = "lrwxr-xr-- 31 997 997 4096 Feb 01 13:47 linkTo -> this";
......
...@@ -4,8 +4,15 @@ import static org.junit.Assert.assertTrue; ...@@ -4,8 +4,15 @@ import static org.junit.Assert.assertTrue;
import org.junit.Test; import org.junit.Test;
/**
* Tests de la classe FTP
* @author Matthias Severin
*/
public class FTPTest { public class FTPTest {
/**
* Test de getIpFromData
*/
@Test @Test
public void testGetIpFromData() { public void testGetIpFromData() {
String data = "227 Entering Passive Mode (91,189,88,142,36,60)."; String data = "227 Entering Passive Mode (91,189,88,142,36,60).";
...@@ -17,6 +24,9 @@ public class FTPTest { ...@@ -17,6 +24,9 @@ public class FTPTest {
assertTrue(ip.equals("84.179.92.132")); assertTrue(ip.equals("84.179.92.132"));
} }
/**
* Test de getPortFromData
*/
@Test @Test
public void testGetPortFromData() { public void testGetPortFromData() {
String data = "227 Entering Passive Mode (91,189,88,142,36,60)."; String data = "227 Entering Passive Mode (91,189,88,142,36,60).";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment