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

deuxième rendu

parent 3545461f
Branches
Tags Projet2_Deuxième_rendu
No related merge requests found
Showing
with 214 additions and 8 deletions
...@@ -6,7 +6,7 @@ import sr.projet2.Server.ConnectionServer; ...@@ -6,7 +6,7 @@ import sr.projet2.Server.ConnectionServer;
public class Main { public class Main {
public static void main(String[] args) throws IOException{ public static void main(String[] args) throws IOException{
ConnectionServer server=new ConnectionServer(2000); ConnectionServer server=new ConnectionServer(2020);
server.serverConnect(); server.serverConnect();
} }
......
package sr.projet2.Request;
import java.io.IOException;
import sr.projet2.Server.FtpConnexion;
public class AUTH_SSL implements request {
private FtpConnexion ftp;
public AUTH_SSL(FtpConnexion ftp) {
this.ftp =ftp;
}
@Override
public void send() throws IOException{
if (this.ftp.getSocket() == null ) {
throw new IOException("Ftp server error");
}
try {
this.ftp.getBufferedWriter().write("530 please login with USER AND PASS.\r\n");
this.ftp.getBufferedWriter().flush();
}
catch(IOException e){
throw new IOException("Connexion failed");
}
}
}
package sr.projet2.Request;
import java.io.IOException;
import sr.projet2.Server.FtpConnexion;
public class AUTH_TLS implements request {
private FtpConnexion ftp;
public AUTH_TLS(FtpConnexion ftp) {
this.ftp =ftp;
}
@Override
public void send() throws IOException{
if (this.ftp.getSocket() == null ) {
throw new IOException("Ftp server error");
}
try {
this.ftp.getBufferedWriter().write("530 please login with USER AND PASS.\r\n");
this.ftp.getBufferedWriter().flush();
}
catch(IOException e){
throw new IOException("Connexion failed");
}
}
}
package sr.projet2.Request;
import java.io.IOException;
import sr.projet2.Server.FtpConnexion;
public class PASS implements request {
private FtpConnexion ftp;
public PASS(FtpConnexion ftp) {
this.ftp =ftp;
}
@Override
public void send() throws IOException{
if (this.ftp.getSocket() == null ) {
throw new IOException("Ftp server error");
}
try {
this.ftp.getBufferedWriter().write("Login successful.\r\n");
this.ftp.getBufferedWriter().flush();
}
catch(IOException e){
throw new IOException("Connexion failed");
}
}
}
package sr.projet2.Request;
import java.io.IOException;
import sr.projet2.Server.FtpConnexion;
public class USER implements request {
private FtpConnexion ftp;
public USER(FtpConnexion ftp) {
this.ftp =ftp;
}
@Override
public void send() throws IOException{
if (this.ftp.getSocket() == null ) {
}
try {
this.ftp.getBufferedWriter().write("331 PLEASE SPECIFY THE PASSWORD.");
this.ftp.getBufferedWriter().flush();
}
catch(IOException e){
throw new IOException("Connexion failed");
}
}
}
package sr.projet2.Request;
import java.io.IOException;
public interface request {
public void send() throws IOException;
}
...@@ -33,8 +33,8 @@ public class ConnectionServer { ...@@ -33,8 +33,8 @@ public class ConnectionServer {
Socket socket=this.srvSckt.accept(); Socket socket=this.srvSckt.accept();
BufferedReader bfR =new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedReader bfR =new BufferedReader(new InputStreamReader(socket.getInputStream()));
BufferedWriter bfW = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); BufferedWriter bfW = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
bfW.write("220 FTP SERVER\r\n"); FtpConnexion ftp= new FtpConnexion(socket, bfR, bfW);
bfW.flush(); ftp.start();
} }
catch(IOException e){ catch(IOException e){
e.printStackTrace(); e.printStackTrace();
......
package sr.projet2.Server;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.net.Socket;
import sr.projet2.Request.AUTH_SSL;
import sr.projet2.Request.AUTH_TLS;
import sr.projet2.Request.PASS;
import sr.projet2.Request.USER;
public class FtpConnexion extends Thread {
private Socket socket;
private BufferedReader bfR;
private BufferedWriter bfW;
public FtpConnexion(Socket socket,BufferedReader bfR,BufferedWriter bfW) {
this.socket=socket;
this.bfR=bfR;
this.bfW=bfW;
}
public void auth() throws IOException{
try {
this.bfW.write("220 FTP SERVER\r\n");
this.bfW.flush();
}catch(IOException e) {
throw new IOException("FTP Connexion failed");
}
}
public void run() {
try {
this.auth();
} catch (IOException e) {
e.printStackTrace();
}
while(true) {
try {
String Read = this.bfR.readLine();
this.read(Read);
} catch (IOException e) {
e.printStackTrace();
}
}
}
public void read(String s) throws IOException {
if(s.startsWith("AUTH TLS")) {
AUTH_TLS request= new AUTH_TLS(this);
request.send();
}
else if (s.startsWith("AUTH SSL")){
AUTH_SSL request= new AUTH_SSL(this);
request.send();
}
else if (s.startsWith("USER")){
USER request= new USER(this);
request.send();
}
else if (s.startsWith("PASS")){
PASS request= new PASS(this);
request.send();
}
}
public Socket getSocket() {
return this.socket;
}
public BufferedWriter getBufferedWriter() {
return this.bfW;
}
public BufferedReader getBufferedReader() {
return this.bfR;
}
}
No preview for this file type
File added
File added
File added
File added
File added
No preview for this file type
File added
/home/hocine/eclipse-workspace/serveurFTP/src/main/java/sr/projet2/Server/ConnectionServer.java /home/hocine/eclipse-workspace/serveurFTP/src/main/java/sr/projet2/Server/ConnectionServer.java
/home/hocine/eclipse-workspace/serveurFTP/src/main/java/sr/projet2/Request/USER.java
/home/hocine/eclipse-workspace/serveurFTP/src/main/java/sr/projet2/Main.java /home/hocine/eclipse-workspace/serveurFTP/src/main/java/sr/projet2/Main.java
/home/hocine/eclipse-workspace/serveurFTP/src/main/java/sr/projet2/Request/AUTH_TLS.java
/home/hocine/eclipse-workspace/serveurFTP/src/main/java/sr/projet2/Request/request.java
/home/hocine/eclipse-workspace/serveurFTP/src/main/java/sr/projet2/Request/PASS.java
/home/hocine/eclipse-workspace/serveurFTP/src/main/java/sr/projet2/Request/AUTH_SSL.java
/home/hocine/eclipse-workspace/serveurFTP/src/main/java/sr/projet2/Server/FtpConnexion.java
No preview for this file type
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<testsuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd" name="sr.projet2.AppTest" time="0.033" tests="1" errors="0" skipped="0" failures="0"> <testsuite xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd" name="sr.projet2.AppTest" time="0.036" tests="1" errors="0" skipped="0" failures="0">
<properties> <properties>
<property name="sun.desktop" value="gnome"/> <property name="sun.desktop" value="gnome"/>
<property name="awt.toolkit" value="sun.awt.X11.XToolkit"/> <property name="awt.toolkit" value="sun.awt.X11.XToolkit"/>
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
<property name="sun.java.launcher" value="SUN_STANDARD"/> <property name="sun.java.launcher" value="SUN_STANDARD"/>
<property name="user.country" value="FR"/> <property name="user.country" value="FR"/>
<property name="sun.boot.library.path" value="/usr/lib/jvm/java-11-openjdk-amd64/lib"/> <property name="sun.boot.library.path" value="/usr/lib/jvm/java-11-openjdk-amd64/lib"/>
<property name="sun.java.command" value="/home/hocine/eclipse-workspace/serveurFTP/target/surefire/surefirebooter14701359487179658639.jar /home/hocine/eclipse-workspace/serveurFTP/target/surefire 2021-02-11T00-09-40_142-jvmRun1 surefire2274530294192485131tmp surefire_017171065220829500292tmp"/> <property name="sun.java.command" value="/home/hocine/eclipse-workspace/serveurFTP/target/surefire/surefirebooter4822591889526926263.jar /home/hocine/eclipse-workspace/serveurFTP/target/surefire 2021-02-18T00-17-01_812-jvmRun1 surefire473336015518436635tmp surefire_0141794290096130823tmp"/>
<property name="jdk.debug" value="release"/> <property name="jdk.debug" value="release"/>
<property name="surefire.test.class.path" value="/home/hocine/eclipse-workspace/serveurFTP/target/test-classes:/home/hocine/eclipse-workspace/serveurFTP/target/classes:/home/hocine/.m2/repository/junit/junit/4.11/junit-4.11.jar:/home/hocine/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar:"/> <property name="surefire.test.class.path" value="/home/hocine/eclipse-workspace/serveurFTP/target/test-classes:/home/hocine/eclipse-workspace/serveurFTP/target/classes:/home/hocine/.m2/repository/junit/junit/4.11/junit-4.11.jar:/home/hocine/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar:"/>
<property name="sun.cpu.endian" value="little"/> <property name="sun.cpu.endian" value="little"/>
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
<property name="java.specification.name" value="Java Platform API Specification"/> <property name="java.specification.name" value="Java Platform API Specification"/>
<property name="java.vm.specification.vendor" value="Oracle Corporation"/> <property name="java.vm.specification.vendor" value="Oracle Corporation"/>
<property name="java.awt.graphicsenv" value="sun.awt.X11GraphicsEnvironment"/> <property name="java.awt.graphicsenv" value="sun.awt.X11GraphicsEnvironment"/>
<property name="surefire.real.class.path" value="/home/hocine/eclipse-workspace/serveurFTP/target/surefire/surefirebooter14701359487179658639.jar"/> <property name="surefire.real.class.path" value="/home/hocine/eclipse-workspace/serveurFTP/target/surefire/surefirebooter4822591889526926263.jar"/>
<property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/> <property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/>
<property name="java.runtime.version" value="11.0.10+9-Ubuntu-0ubuntu1.20.04"/> <property name="java.runtime.version" value="11.0.10+9-Ubuntu-0ubuntu1.20.04"/>
<property name="user.name" value="hocine"/> <property name="user.name" value="hocine"/>
...@@ -57,5 +57,5 @@ ...@@ -57,5 +57,5 @@
<property name="sun.io.unicode.encoding" value="UnicodeLittle"/> <property name="sun.io.unicode.encoding" value="UnicodeLittle"/>
<property name="java.class.version" value="55.0"/> <property name="java.class.version" value="55.0"/>
</properties> </properties>
<testcase name="shouldAnswerWithTrue" classname="sr.projet2.AppTest" time="0.001"/> <testcase name="shouldAnswerWithTrue" classname="sr.projet2.AppTest" time="0.002"/>
</testsuite> </testsuite>
\ No newline at end of file
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Test set: sr.projet2.AppTest Test set: sr.projet2.AppTest
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.033 s - in sr.projet2.AppTest Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.036 s - in sr.projet2.AppTest
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment