Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.net.Socket;
- import java.util.StringTokenizer;
- public class Client
- {
- public static Boolean PWD(PrintWriter writer, BufferedReader br) throws IOException
- {
- String str = new String();
- writer.println("PWD");
- str = br.readLine();
- if(str.substring(0,3).equals("257")){
- System.out.println("PWD : "+str.substring(3));
- return true;
- }
- return false;
- }
- public static Boolean CWD(PrintWriter writer, BufferedReader br) throws IOException
- {
- String str = new String();
- writer.println("CWD "+"WinXp");
- str = br.readLine();
- //System.out.println(str);
- if(str.substring(0,3).equals("250")){
- System.out.println(str.substring(3));
- return true;
- }
- return false;
- }
- public static Boolean PASV(PrintWriter writer, BufferedReader br) throws IOException
- {
- String str = new String();
- int j=0;
- String tabString[]=new String[5];
- writer.println("PASV"+str);
- str = br.readLine();
- StringTokenizer ip = new StringTokenizer(str, "(), ABCDEFGHIJKLMOPQRSTUVWXYZabcdefghijklmnopkrstuvwxyz");
- //ABCDEFGHIJKLMOPQRSTUVWXYZabcdefghijklmnopkrstuvwxyz
- for(int i=0;i<3;i++){
- ip.nextToken();
- }
- while(ip.hasMoreTokens())
- {
- tabString[j]=ip.nextToken();
- System.out.print(tabString[j]+".");
- j++;
- }
- if(str.substring(0,3).equals("227")){
- System.out.println(str.substring(3));
- return true;
- }
- return false;
- }
- public static Boolean QUIT(PrintWriter writer, BufferedReader br) throws IOException
- {
- String str = new String();
- writer.println("QUIT");
- str = br.readLine();
- if(str.substring(0,3).equals("221")){
- System.out.println(str.substring(3));
- return true;
- }
- return false;
- }
- public static Boolean connexion(PrintWriter writer, BufferedReader br) throws IOException
- {
- BufferedReader entree = new BufferedReader(new InputStreamReader(System.in));
- String str = new String();
- //String user = "e20703933";
- //String pass = "pemeenam1";
- String response = new String();
- response = br.readLine();
- System.out.println(response.substring(0, 3));
- if(response.substring(0,3).equals("220"))
- {
- System.out.print("Username : ");
- str = entree.readLine();
- writer.println("USER "+str);
- response = br.readLine();
- if(response.substring(0,3).equals("331"))
- {
- System.out.print("Password : ");
- str = entree.readLine();
- writer.println("PASS "+str);
- response = br.readLine();
- //System.out.print(response);
- if(response.substring(0,3).equals("230"))
- {
- System.out.println("Connection successfull !");
- return true;
- }
- System.out.println("Wrong password");
- return false;
- }
- return false;
- }
- System.out.println(response);
- return false;
- }
- public static void main(String [] args) {
- System.getProperties().put("http.proxyHost", "proxyubo.univ-brest.fr");
- System.getProperties().put("http.proxyPort", "3128");
- try{
- String addr = "stockage.univ-brest.fr";
- Socket sock = new Socket(addr,21);
- PrintWriter writer = new PrintWriter(
- new BufferedWriter(
- new OutputStreamWriter(sock.getOutputStream())),
- true);
- BufferedReader br = new BufferedReader(
- new InputStreamReader(sock.getInputStream())
- );
- if(connexion(writer,br)){
- if(PWD(writer,br))
- {
- if(CWD(writer,br))
- {
- if(PWD(writer,br))
- {
- if(PASV(writer,br)){
- QUIT(writer,br);
- }
- }
- }
- }
- }
- writer.println("END") ;
- br.close();
- writer.close();
- sock.close();
- }catch (IOException ioe){}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement