Skip to content
Snippets Groups Projects
Commit fba31209 authored by Ferhat Hocine's avatar Ferhat Hocine
Browse files

rendu final

parent 995e58da
No related merge requests found
Showing
with 434 additions and 156 deletions
Projet nº1 - Application «Tree FTP»
Ferhat HOCINE GL02 Ferhat HOCINE GL02
2021
*** 1/ Introduction
I)objectif:
L'Application «Tree FTP» a pour résultat l'affichage de l'arborescence d'un répertoire accessible via le protocole applicatif (FTP) depuis un shell graçe a une commande.
cette commande prend en paramètre obligatoirement l'adresse du serveur FTP + en option un nom d'utilisateur et un mot de passe
II)exécution:
Dans le fichier racine on exécute la commande :
->>> mvn package
//pour compliler le projet
puis la commande :
->>> mvn javadoc:javadoc
//pour générer la documentation:
puis la commande :
java -jar target/projet1.sr-1.0-SNAPSHOT.jar ftp.ubuntu.com
//pour lancer l'application sur le server FTP ubuntu
ou la commande :
java -jar target/projet1.sr-1.0-SNAPSHOT.jar ftp.free.fr
//pour le server FTP Free
*** 2/ Architecture
la gestion d'erreur:
La plus part des méthodes de la classe connection renvoie IOException avec un message en cas d'erreur.
exemple:
la méthode envoyerPWD() qui envoie la commande "PWD"
public void envoyerPWD() throws IOException {
if (this.socket==null) {
System.out.println("Erreur connection FTP Server !!");
}
else {
printer.write("PWD\r\n");
printer.flush();
try {
String r = this.bfR.readLine();
}
catch(IOException e) {
throw new IOException("Buffer reader error");
}
}
}
Dans la méthode envoyerPWD lors de la lecture de la réponse par le buffer reader en cas de IOException il sera attraper par le catch et renvera un new IOException avec le message "Buffer reader error".
la capture d'erreure est de même pour toutes les méthode de la classe connection
*** 3/ Parcours du code (code samples)
a) la méthode envoyerCWD(String dossier) de la classe Connection::
cette méthode utilise le String dossier passé en paramètre pour envoyé un cammande CWD +dossier afin de savoir si on peut accédé ou dossier dant le nom est passé en paramètre ou l'accès est interdit et la réponse est renvoyé sous forme de boolean par la méthode.
public boolean envoyerCWD(String dossier) throws IOException {
if (this.socket==null) {
System.out.println("Erreur connection FTP Server !!");
}
else {
try {
printer.write("CWD "+dossier+"\r\n");
printer.flush();
String r = this.bfR.readLine();
return r.startsWith("250");
}
catch(IOException e) {
throw new IOException("Buffer reader error");
}
catch (NullPointerException e){
return false;
}
}
return false;
}
b) la méthode envoyerPASV() de la classe Connection:
cette méthode envoie la commande PASV afin de passer au mode passive. en cas de réussite les information récupérer sont renvoyé dans le cas contraire l'exception est levée.
public String envoyerPASV() throws IOException {
if (this.socket==null) {
System.out.println("Erreur connection FTP Server !!");
return "";
}
else {
try {
printer.write("PASV\r\n");
printer.flush();
String r = this.bfR.readLine();
return r;
}
catch(IOException e) {
throw new IOException("Buffer reader error");
}
}
}
c) la méthode getAdressePasv() de la classe Connection:
cette méthode utilise le string (PASV) passé en paramètre qui représente une réponse de la commande PASV et extrait l'adresse IP compris dans le message.
public String getAdressePasv(String PASV) {
int i = PASV.indexOf("(");
int j = PASV.indexOf(")");
PASV= PASV.substring(i+1,j);
String [] str=PASV.split(",");
String res="";
for (i=0; i<4; i++) {
res+=str[i]+".";
}
res=res.substring(0,res.length()-1);
return res;
}
d) la méthode envoyerList(String adrs, int port) de la classe Connection:
cette methode utilise l'adresse ip et le port (passées en paramètre )extrait depuis la réponse de la commande PASV afin de retourner la liste des élements contenu dans la dossier encours
public ArrayList<String> envoyerList(String adrs, int port) throws IOException {
ArrayList<String> Readl=new ArrayList<String>();
if (this.socket==null) {
System.out.println("Erreur connection FTP Server !!");
return Readl;
}
else {
try {
printer.write("LIST\r\n");
printer.flush();
Readl=this.newConnection(adrs, port);
String r = this.bfR.readLine();
r = this.bfR.readLine();
return Readl;
}
catch(IOException e) {
throw new IOException("Buffer reader error");
}
}
}
e)la méthode NameOperation(String s)de la classe Arbre:
cette méthode transforme le string passé en paramètre qui représentre un ligne d'information d'un élement(fichier, dossier, lien ...) en liste avec les partie séparées et dans espace.
public String[] NameOperation(String s){
s=s.replaceAll(" ",",");
while(s.indexOf(",,")!=-1) {
s=s.replaceAll(",,",",");
}
return s.split(",");
}
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>projet1.sr</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
encoding/<project>=UTF-8
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>systemes.repartie.tree.ftp</groupId>
<artifactId>projet1.sr</artifactId>
<version>1.0-SNAPSHOT</version>
<name>projet1.sr</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
File deleted
File deleted
projet1.sr/doc/Diagram.jpg

53.6 KiB

<?xml version="1.0" encoding="UTF-8"?>
<class-diagram version="1.2.4" icons="true" automaticImage="JPEG" always-add-relationships="false"
generalizations="true" realizations="true" associations="true" dependencies="false" nesting-relationships="true"
router="FAN">
<class id="1" language="java" name="systemes.repartie.tree.ftp.Main" project="projet1.sr"
file="/projet1.sr/src/main/java/systemes/repartie/tree/ftp/Main.java" binary="false" corner="BOTTOM_RIGHT">
<position height="97" width="118" x="138" y="115"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="2" language="java" name="systemes.repartie.tree.ftp.Arbre.Arbre" project="projet1.sr"
file="/projet1.sr/src/main/java/systemes/repartie/tree/ftp/Arbre/Arbre.java" binary="false" corner="BOTTOM_RIGHT">
<position height="151" width="175" x="296" y="115"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="3" language="java" name="systemes.repartie.tree.ftp.ParametreConnection.ConnectionParametre"
project="projet1.sr"
file="/projet1.sr/src/main/java/systemes/repartie/tree/ftp/ParametreConnection/ConnectionParametre.java"
binary="false" corner="BOTTOM_RIGHT">
<position height="223" width="243" x="228" y="731"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<class id="4" language="java" name="systemes.repartie.tree.ftp.FtpConnection.Connection" project="projet1.sr"
file="/projet1.sr/src/main/java/systemes/repartie/tree/ftp/FtpConnection/Connection.java" binary="false"
corner="BOTTOM_RIGHT">
<position height="385" width="243" x="228" y="306"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</display>
</class>
<association id="5">
<end type="SOURCE" refId="4" navigable="false">
<attribute id="6" name="connect"/>
<multiplicity id="7" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="3" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="8">
<end type="SOURCE" refId="2" navigable="false">
<attribute id="9" name="connect"/>
<multiplicity id="10" minimum="0" maximum="1"/>
</end>
<end type="TARGET" refId="4" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/>
</classifier-display>
<association-display labels="true" multiplicity="true"/>
</class-diagram>
\ No newline at end of file
...@@ -35,10 +35,20 @@ ...@@ -35,10 +35,20 @@
<artifactId>maven-clean-plugin</artifactId> <artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version> <version>3.1.0</version>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<reportOutputDirectory>${project.build.directory}/docs</reportOutputDirectory>
<destDir>docs</destDir>
<nohelp>true</nohelp>
</configuration>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --> <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin> <plugin>
<artifactId>maven-resources-plugin</artifactId> <artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version> <version>3.1.0</version>
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
...@@ -50,7 +60,8 @@ ...@@ -50,7 +60,8 @@
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-jar-plugin</artifactId> <artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version> <version>3.0.2</version><configuration><archive><manifest><mainClass>systemes.repartie.tree.ftp.Main</mainClass></manifest></archive></configuration>
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-install-plugin</artifactId> <artifactId>maven-install-plugin</artifactId>
...@@ -65,10 +76,12 @@ ...@@ -65,10 +76,12 @@
<artifactId>maven-site-plugin</artifactId> <artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version> <version>3.7.1</version>
</plugin> </plugin>
<plugin> <plugin>
<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>
</plugins> </plugins>
</pluginManagement> </pluginManagement>
</build> </build>
......
...@@ -4,17 +4,29 @@ import java.io.IOException; ...@@ -4,17 +4,29 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import systemes.repartie.tree.ftp.FtpConnection.Connection; import systemes.repartie.tree.ftp.FtpConnection.Connection;
/**
* class to display the tree of our repetory
* @author hocine
*
*/
public class Arbre { public class Arbre {
// variable declaration
private Connection connect; private Connection connect;
//constructor
public Arbre(Connection connect) { public Arbre(Connection connect) {
this.connect=connect; this.connect=connect;
} }
//getter
public Connection getConnection() { public Connection getConnection() {
return this.connect; return this.connect;
} }
/*
* brows our repertory and display the tree of every file, directory or link using TypeOf methode
* params space : to put space between parent and children files
* @throws IOException
*/
public void getTree(String space) throws IOException { public void getTree(String space) throws IOException {
this.connect.envoyerType(); this.connect.envoyerType();
String mySTring = this.connect.envoyerPASV(); String mySTring = this.connect.envoyerPASV();
...@@ -28,6 +40,13 @@ public class Arbre { ...@@ -28,6 +40,13 @@ public class Arbre {
} }
} }
} }
/*
* Display the type of file in the param given (file "F",Directory "D" or Link "L"
* param space : to put space between parent and children files
* param s : pemission and type of file
* @throws IOException
*/
public void TypeOf(String s,String space) throws IOException { public void TypeOf(String s,String space) throws IOException {
String[] myline=NameOperation(s); String[] myline=NameOperation(s);
...@@ -48,6 +67,13 @@ public class Arbre { ...@@ -48,6 +67,13 @@ public class Arbre {
} }
} }
/*
* Operation on String param to delete space and put "," between parts and finaly make it String[]
* params s
* @return String[]
*/
public String[] NameOperation(String s){ public String[] NameOperation(String s){
s=s.replaceAll(" ",","); s=s.replaceAll(" ",",");
while(s.indexOf(",,")!=-1) { while(s.indexOf(",,")!=-1) {
......
...@@ -18,7 +18,7 @@ import systemes.repartie.tree.ftp.ParametreConnection.ConnectionParametre; ...@@ -18,7 +18,7 @@ import systemes.repartie.tree.ftp.ParametreConnection.ConnectionParametre;
* *
*/ */
public class Connection { public class Connection {
// parames // variable declaration
private ConnectionParametre connect; private ConnectionParametre connect;
private Socket socket; private Socket socket;
private BufferedReader bfR; private BufferedReader bfR;
...@@ -32,18 +32,17 @@ public class Connection { ...@@ -32,18 +32,17 @@ public class Connection {
} }
/* /**
* return the instance of ConnectionParametre used by our class * return the instance of ConnectionParametre used by our class
*/ */
public ConnectionParametre getConnectionParam() { public ConnectionParametre getConnectionParam() {
return this.connect; return this.connect;
} }
/* /**
* Connexion to ftp server methode * Connexion to ftp server methode
* this methode uses our instance of ConnectionParametre to connect to ftp server * this methode uses our instance of ConnectionParametre to connect to ftp server
* @throws IOException * @throws IOException
* @return void
*/ */
public void OperationConnection() throws IOException{ public void OperationConnection() throws IOException{
//creating a new instance of socket using ConnectionParametre adress and port //creating a new instance of socket using ConnectionParametre adress and port
...@@ -90,26 +89,29 @@ public class Connection { ...@@ -90,26 +89,29 @@ public class Connection {
} }
} }
/* /**
* executing PWD commande to get repertory root * executing PWD commande to get repertory root
* @throws IOException * @throws IOException
* @return void
*/ */
public void envoyerPWD() throws IOException { public void envoyerPWD() throws IOException {
if (this.socket==null) { if (this.socket==null) {
System.out.println("Erreur connection FTP Server !!"); System.out.println("Erreur connection FTP Server !!");
} }
else { else {
try {
printer.write("PWD\r\n"); printer.write("PWD\r\n");
printer.flush(); printer.flush();
String r = this.bfR.readLine(); String r = this.bfR.readLine();
//System.out.println(r); }
catch(IOException e) {
throw new IOException("Buffer reader error");
}
} }
} }
/* /**
* executing CWD command using the directory given in param to access to it * executing CWD command using the directory given in param to access to it
* @param String : dossier * @param dossier
* @throws IOException * @throws IOException
* @return boolean : True if it succeed to access to the directory or False if it failed * @return boolean : True if it succeed to access to the directory or False if it failed
*/ */
...@@ -118,15 +120,24 @@ public class Connection { ...@@ -118,15 +120,24 @@ public class Connection {
System.out.println("Erreur connection FTP Server !!"); System.out.println("Erreur connection FTP Server !!");
} }
else { else {
try {
printer.write("CWD "+dossier+"\r\n"); printer.write("CWD "+dossier+"\r\n");
printer.flush(); printer.flush();
String r = this.bfR.readLine(); String r = this.bfR.readLine();
return r.startsWith("250"); return r.startsWith("250");
}
catch(IOException e) {
throw new IOException("Buffer reader error");
}
catch (NullPointerException e){
return false;
}
} }
return false; return false;
} }
/* /**
* executing PASV command to enter to passive mode * executing PASV command to enter to passive mode
* @throws IOException * @throws IOException
* @return String : the information received in passive mode * @return String : the information received in passive mode
...@@ -137,12 +148,16 @@ public class Connection { ...@@ -137,12 +148,16 @@ public class Connection {
return ""; return "";
} }
else { else {
try {
printer.write("PASV\r\n"); printer.write("PASV\r\n");
printer.flush(); printer.flush();
String r = this.bfR.readLine(); String r = this.bfR.readLine();
//System.out.println(r);
return r; return r;
} }
catch(IOException e) {
throw new IOException("Buffer reader error");
}
}
} }
/* /*
...@@ -177,17 +192,20 @@ public class Connection { ...@@ -177,17 +192,20 @@ public class Connection {
/* /*
* executing TYPE I command to switch to the binary mode * executing TYPE I command to switch to the binary mode
* @throws IOException * @throws IOException
* @return void
*/ */
public void envoyerType() throws IOException { public void envoyerType() throws IOException {
if (this.socket==null) { if (this.socket==null) {
System.out.println("Erreur connection FTP Server !!"); System.out.println("Erreur connection FTP Server !!");
} }
else { else {
try {
printer.write("TYPE I\r\n"); printer.write("TYPE I\r\n");
printer.flush(); printer.flush();
String r = this.bfR.readLine(); String r = this.bfR.readLine();
//System.out.println(r); }
catch(IOException e) {
throw new IOException("Buffer reader error");
}
} }
} }
...@@ -200,56 +218,70 @@ public class Connection { ...@@ -200,56 +218,70 @@ public class Connection {
ArrayList<String> Readl=new ArrayList<String>(); ArrayList<String> Readl=new ArrayList<String>();
if (this.socket==null) { if (this.socket==null) {
System.out.println("Erreur connection FTP Server !!"); System.out.println("Erreur connection FTP Server !!");
return Readl;
} }
else { else {
try {
printer.write("LIST\r\n"); printer.write("LIST\r\n");
printer.flush(); printer.flush();
Readl=this.newConnection(adrs, port); Readl=this.newConnection(adrs, port);
String r = this.bfR.readLine(); String r = this.bfR.readLine();
r = this.bfR.readLine(); r = this.bfR.readLine();
}
return Readl; return Readl;
} }
catch(IOException e) {
throw new IOException("Buffer reader error");
}
}
}
/* /*
* executing Cdup To change directory * executing Cdup To change directory
* @throws IOException * @throws IOException
* @return void
*/ */
public void envoyerCdup() throws IOException { public void envoyerCdup() throws IOException {
if (this.socket==null) { if (this.socket==null) {
System.out.println("Erreur connection FTP Server !!"); System.out.println("Erreur connection FTP Server !!");
} }
else { else {
try {
printer.write("CDUP\r\n"); printer.write("CDUP\r\n");
printer.flush(); printer.flush();
String r = this.bfR.readLine(); String r = this.bfR.readLine();
//System.out.println(r); }
catch(IOException e) {
throw new IOException("Buffer reader error");
}
} }
} }
/* /*
* executing Quit To QUIT socket * executing Quit To QUIT socket
* @throws IOException * @throws IOException
* @return void
*/ */
public void envoyerQuit() throws IOException { public void envoyerQuit() throws IOException {
if (this.socket==null) { if (this.socket==null) {
System.out.println("Erreur connection FTP Server !!"); System.out.println("Erreur connection FTP Server !!");
} }
else { else {
try {
printer.write("QUIT\r\n"); printer.write("QUIT\r\n");
printer.flush(); printer.flush();
String r = this.bfR.readLine(); String r = this.bfR.readLine();
//System.out.println(r); }
catch(IOException e) {
throw new IOException("Buffer reader error");
}
} }
} }
/* /*
* Staring new socket the to get the List of file,directory and link in our repertory from IP Address and Port * Staring new socket the to get the List of file,directory and link in our repertory from IP Address and Port
* @param String Adresse : IP address * @param Adresse : IP address
* @param STring Port : port * @param Port : port
* @throws IOException * @throws IOException
* @return ArrayList<String> : The List of file,directory and link in our repertory from IP Address and Port * @return ArrayList<String> : The List of file,directory and link in our repertory from IP Address and Port
*/ */
...@@ -259,6 +291,7 @@ public class Connection { ...@@ -259,6 +291,7 @@ public class Connection {
BufferedReader bfR1 = new BufferedReader(new InputStreamReader(socket1.getInputStream())); BufferedReader bfR1 = new BufferedReader(new InputStreamReader(socket1.getInputStream()));
OutputStream outPut1 = socket1.getOutputStream(); OutputStream outPut1 = socket1.getOutputStream();
PrintWriter printer1 = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket1.getOutputStream()))); PrintWriter printer1 = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket1.getOutputStream())));
try {
String r = bfR1.readLine(); String r = bfR1.readLine();
while (r!=null) { while (r!=null) {
liste.add(r); liste.add(r);
...@@ -268,6 +301,10 @@ public class Connection { ...@@ -268,6 +301,10 @@ public class Connection {
printer1.flush(); printer1.flush();
return liste; return liste;
} }
catch(IOException e) {
throw new IOException("Buffer reader error");
}
}
/* /*
* Close Socket * Close Socket
......
...@@ -12,10 +12,22 @@ import java.net.Socket; ...@@ -12,10 +12,22 @@ import java.net.Socket;
import systemes.repartie.tree.ftp.Arbre.Arbre; import systemes.repartie.tree.ftp.Arbre.Arbre;
import systemes.repartie.tree.ftp.FtpConnection.Connection; import systemes.repartie.tree.ftp.FtpConnection.Connection;
import systemes.repartie.tree.ftp.ParametreConnection.ConnectionParametre; import systemes.repartie.tree.ftp.ParametreConnection.ConnectionParametre;
/**
* Main
* @author hocine
*
*/
public class Main { public class Main {
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
ConnectionParametre connectPar= new ConnectionParametre("anonymous","anonymous",21,args[0]); String user="anonymous";
String pass="anonymous";
if(args.length>1) {
user=args[1];
}
if(args.length>2) {
pass=args[2];
}
ConnectionParametre connectPar= new ConnectionParametre(user,pass,21,args[0]);
Connection connect= new Connection(connectPar); Connection connect= new Connection(connectPar);
System.out.println("-------------Connection-------------"); System.out.println("-------------Connection-------------");
connect.OperationConnection(); connect.OperationConnection();
......
package systemes.repartie.tree.ftp.ParametreConnection; package systemes.repartie.tree.ftp.ParametreConnection;
/**
* Params class to identify user
* @author hocine
*
*/
public class ConnectionParametre { public class ConnectionParametre {
// variable declaration
private String identifiant; private String identifiant;
private String motdepasse; private String motdepasse;
private String adresse; private String adresse;
private int port; private int port;
//Constructor
public ConnectionParametre(String identifiant,String motdepasse,int port,String adresse) { public ConnectionParametre(String identifiant,String motdepasse,int port,String adresse) {
this.identifiant=identifiant; this.identifiant=identifiant;
this.motdepasse=motdepasse; this.motdepasse=motdepasse;
...@@ -13,6 +19,8 @@ public class ConnectionParametre { ...@@ -13,6 +19,8 @@ public class ConnectionParametre {
this.adresse=adresse; this.adresse=adresse;
} }
//getters
public String getIdentifiant() { public String getIdentifiant() {
return this.identifiant; return this.identifiant;
} }
......
package systemes.repartie.tree.ftp.FtpConnection;
import org.junit.Test;
import systemes.repartie.tree.ftp.ParametreConnection.ConnectionParametre;
import static org.junit.Assert.*;
import java.io.IOException;
public class ConnectionTest {
public static ConnectionParametre connect=new ConnectionParametre("anonymous","anonymous",21,"ftp.ubuntu.com");
public static Connection connectFtp= new Connection(connect);
@Test
public void getConnectionParamTest() {
assertEquals(connectFtp.getConnectionParam().getIdentifiant(), "anonymous");
}
@Test
public void envoyerCWD() throws IOException {
connectFtp.OperationConnection();
assertFalse(connectFtp.envoyerCWD("nonExistingRepertory"));
}
@Test
public void envoyerPASV_envoyerType() throws IOException {
connectFtp.OperationConnection();
connectFtp.envoyerType();
connectFtp.OperationConnection();
String line =connectFtp.envoyerPASV();
assertTrue(line.startsWith("227 Entering Passive Mode"));
}
}
package systemes.repartie.tree.ftp.ParametreConnection;
import org.junit.Test;
import static org.junit.Assert.*;
public class ConnectionParametreTest {
public static ConnectionParametre connect=new ConnectionParametre("anonymous","anonymous",21,"ftp.ubuntu.com");
@Test
public void getIdentifiantTest() {
assertEquals(connect.getIdentifiant(), "anonymous");
}
@Test
public void getMotdepasseTest() {
assertEquals(connect.getMotdepasse(), "anonymous");
}
@Test
public void getAdresseTest() {
assertEquals(connect.getAdresse(), "ftp.ubuntu.com");
}
@Test
public void getPortTest() {
assertEquals(connect.getPort(), 21);
}
}
File deleted
File deleted
File deleted
#Created by Apache Maven 3.6.3
groupId=systemes.repartie.tree.ftp
artifactId=projet1.sr
version=1.0-SNAPSHOT
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment