In this mini-project, you are asked to develop a simple file transfer protocol.
ID: 3721415 • Letter: I
Question
In this mini-project, you are asked to develop a simple file transfer protocol. The protocol is based on client-server architecture. The client will connect to the server, sending user name and password for authentication (No encryption needed. Sending over plain TCP connection is fine). After passing authentication, the client will be able to download/upload files, list the files in the current directory at the server, and change the current directory to other directory at the server. After the client sends a request, the server should respond with some information to indicate if the request is processed or not. The server should also be able to serve another client after the current client logout.
You are required implement BOTH client and server sides. And your protocol should be able to transfer BOTH ASCII and binary files. You may refer to the FTP protocol for possible design options and typical commands. But no need to strictly follow or fully implement the FTP protocol. You can design your own protocol.
No GUI is required. A command line based UI is good enough.
ONLY use bare socket programming (NOT allow any other supportive libraries/packages such as HTTP or FTP classes). EVERY OTHER ANSWER USES EXTRA LIBRARIES, APACHE, OR FTP CLASSES. DO NOT ANSWER WITH ANY OF THOSE, PLEASE.
Explanation / Answer
Client prog
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;
public class D_TCPClientChat {
public static void main(String args[]) throws Exception
{
Socket sk=new Socket("127.0.0.1",2002);
BufferedReader sin=new BufferedReader(new InputStreamReader(sk.getInputStream()));
PrintStream sout=new PrintStream(sk.getOutputStream());
BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
String s;
while(true)
{
System.out.print("Client : ");
s=stdin.readLine();
sout.println(s);
s=sin.readLine();
System.out.print("Server : "+s+" ");
if (s.equalsIgnoreCase("BYE") )
break;
}
sk.close();
sin.close();
sout.close();
stdin.close();
}
}
Server prog :-
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;
public class D_TCPServerChat
{
public static void main(String args[]) throws Exception
{
ServerSocket ss=new ServerSocket(2002);
Socket sk=ss.accept();
BufferedReader cin=new BufferedReader(new InputStreamReader(sk.getInputStream()));
PrintStream cout=new PrintStream(sk.getOutputStream());
BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
String s;
while(true)
{
s=cin.readLine();
if (s.equalsIgnoreCase("END"))
{
cout.println("BYE");
break;
}
System. out.print("Client : "+s+" ");
System.out.print("Server : ");
s=stdin.readLine();
cout.println(s);
}
ss.close();
sk.close();
cin.close();
cout.close();
stdin.close();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.