Question

In: Computer Science

in Java - implement ftp-server and ftp-client. ftp-server Logging into ftp-server from ftp-client The ftp-server is...

in Java - implement ftp-server and ftp-client.

ftp-server
Logging into ftp-server from ftp-client
The ftp-server is an interactive, command-line program that creates a server socket, and waits for connections.
Once connected, the ftp-client can send and receive files with ftp-server until ftp-client logs out.

Sending and receiving files
The commands sent from the ftp-client to the ftp-server must recognize and handle are these:

rename- the ftp-server responds to this command by renaming the named file in its current directory to the new file name. If the file does not exist, or if the second file name is not provided, ftp-server responds with the string "...huh?..."

ftp-client
When ftp-client starts up, it should connect to the ftp-server using the IP address of the server, and a port number. Once a connection is established, ftp-client should prompt the user with the prompt string, "ftp> ", and wait for keyboard input from the user.

Valid keyboard input includes the commands described in the ftp-server section of this write-up. The ftp-client user uses these commands to send and receive files, get a directory listing from the ftp-server's current directory, and get a help screen.


write the ftp-server first and test with telnet. Once you're satisfied that ftp-server is running, then start working on ftp-client.

Solutions

Expert Solution

Ans :

Giving you the simple solution with two different program server and client. Go through the entire program this will help you a lot ========== Server============= =========================================================== import java.net.*; import java.io.*; import java.util.*; public class FTPS { public static void main(String args[]) throws Exception { ServerSocket soc=new ServerSocket(5217); System.out.println(\"Port Number 5217 started\"); while(true) { System.out.println(\"Connection ==waiting===...\"); transferfile t=new transferfile(soc.accept()); } } } class transferfile extends Thread { Socket ClientSoc; DataInputStream din; DataOutputStream dout; transferfile(Socket soc) { try { ClientSoc=soc; din=new DataInputStream(ClientSoc.getInputStream()); dout=new DataOutputStream(ClientSoc.getOutputStream()); System.out.println(\"Client Connected ...\"); start(); } catch(Exception ex) { } } void SendFile() throws Exception { String filename=din.readUTF(); File f=new File(filename); if(!f.exists()) { dout.writeUTF(\"File Not Found\"); return; } else { dout.writeUTF(\"READY\"); FileInputStream fin=new FileInputStream(f); int ch; do { ch=fin.read(); dout.writeUTF(String.valueOf(ch)); } while(ch!=-1); fin.close(); dout.writeUTF(\"File Receive Successfully\"); } } void ReceiveFile() throws Exception { String filename=din.readUTF(); if(filename.compareTo(\"File not found\")==0) { return; } File f=new File(filename); String option; if(f.exists()) { dout.writeUTF(\"File Already Exists\"); option=din.readUTF(); } else { dout.writeUTF(\"SendFile\"); option=\"Y\"; } if(option.compareTo(\"Y\")==0) { FileOutputStream fout=new FileOutputStream(f); int ch; String temp; do { temp=din.readUTF(); ch=Integer.parseInt(temp); if(ch!=-1) { fout.write(ch); } }while(ch!=-1); fout.close(); dout.writeUTF(\"File Send Successfully\"); } else { return; } } public void run() { while(true) { try { System.out.println(\"Command ==waiting== ...\"); String Command=din.readUTF(); if(Command.compareTo(\"GET\")==0) { System.out.println(\"\\tGET Command Received ...\"); SendFile(); continue; } else if(Command.compareTo(\"SEND\")==0) { System.out.println(\"\\tSEND Command Receiced ...\"); ReceiveFile(); continue; } else if(Command.compareTo(\"DISCONNECT\")==0) { System.out.println(\"\\tDisconnect Command Received ...\"); System.exit(1); } } catch(Exception ex) { } } } }
==========================================

=============== Client==================== ====================================================== import java.net.*; import java.io.*; import java.util.*; class FTPC { public static void main(String args[]) throws Exception { Socket soc=new Socket(\"127.0.0.1\",5217); transferfileClient t=new transferfileClient(soc); t.displayMenu(); } } class transferfileClient { Socket ClientSoc; DataInputStream din; DataOutputStream dout; BufferedReader br; transferfileClient(Socket soc) { try { ClientSoc=soc; din=new DataInputStream(ClientSoc.getInputStream()); dout=new DataOutputStream(ClientSoc.getOutputStream()); br=new BufferedReader(new InputStreamReader(System.in)); } catch(Exception ex) { } } void SendFile() throws Exception { String filename; System.out.print(\"Enter File Name :\"); filename=br.readLine(); File f=new File(filename); if(!f.exists()) { System.out.println(\"File not Exists...\"); dout.writeUTF(\"File not found\"); return; } dout.writeUTF(filename); String msgFromServer=din.readUTF(); if(msgFromServer.compareTo(\"File Already Exists\")==0) { String Option; System.out.println(\"File Already Exists. Want to OverWrite (Y/N) ?\"); Option=br.readLine(); if(Option==\"Y\") { dout.writeUTF(\"Y\"); } else { dout.writeUTF(\"N\"); return; } } System.out.println(\"Sending File ...\"); FileInputStream fin=new FileInputStream(f); int ch; do { ch=fin.read(); dout.writeUTF(String.valueOf(ch)); } while(ch!=-1); fin.close(); System.out.println(din.readUTF()); } void ReceiveFile() throws Exception { String fileName; System.out.print(\"Enter File Name :\"); fileName=br.readLine(); dout.writeUTF(fileName); String msgFromServer=din.readUTF(); if(msgFromServer.compareTo(\"File Not Found\")==0) { System.out.println(\"File not found on Server ...\"); return; } else if(msgFromServer.compareTo(\"READY\")==0) { System.out.println(\"Receiving File ...\"); File f=new File(fileName); if(f.exists()) { String Option; System.out.println(\"File Already Exists. Want to OverWrite (Y/N) ?\"); Option=br.readLine(); if(Option==\"N\") { dout.flush(); return; } } FileOutputStream fout=new FileOutputStream(f); int ch; String temp; do { temp=din.readUTF(); ch=Integer.parseInt(temp); if(ch!=-1) { fout.write(ch); } }while(ch!=-1); fout.close(); System.out.println(din.readUTF()); } } public void displayMenu() throws Exception { while(true) { System.out.println(\"[ MENU ]\"); System.out.println(\"1. Send File\"); System.out.println(\"2. Receive File\"); System.out.println(\"3. Exit\"); System.out.print(\"\\nEnter Choice :\"); int choice; choice=Integer.parseInt(br.readLine()); if(choice==1) { dout.writeUTF(\"SEND\"); SendFile(); } else if(choice==2) { dout.writeUTF(\"GET\"); ReceiveFile(); } else { dout.writeUTF(\"DISCONNECT\"); System.exit(1); } } } }


Related Solutions

How to create a FTP server using python and TCP Ports How to create a FTP...
How to create a FTP server using python and TCP Ports How to create a FTP server using python and UDP Ports
In Java and using JavaFX, write a client/server application with two parts, a server and a...
In Java and using JavaFX, write a client/server application with two parts, a server and a client. Have the client send the server a request to compute whether a number that the user provided is prime. The server responds with yes or no, then the client displays the answer.
The IT manager for the Credit Call Center is planning to implement a client/server architecture to...
The IT manager for the Credit Call Center is planning to implement a client/server architecture to support the operations of the call center. The owner of the company is content with the current setup and reluctant to allocate resources to a client/server architecture. You have been tasked by the IT Manager to explain client/server architecture to the owner and discuss the benefits and how it will help Credit Call Center in your explanation address What is meant by client/server architecture?...
What is the definition of the FTP server? What are the steps to receive the files...
What is the definition of the FTP server? What are the steps to receive the files from the FTP server? Explain and justify jour answer by drawing
In the provided client and server code, the server can serve to single client at a...
In the provided client and server code, the server can serve to single client at a time. You have to change server.java code so that it can connect and serve multiple clients at the same time. Use multithreading. =============================================================================== import java.io.*; import java.net.*; public class Client { public static void main(String[] args) throws IOException { String serverHostname = new String ("127.0.0.1"); if (args.length > 0) { //pass the hsotname through cmd argument serverHostname = args[0]; } System.out.println ("Attemping to connect...
The client connects to the server. The server accepts the connection. The client sends a line...
The client connects to the server. The server accepts the connection. The client sends a line of text containing only SHAKESPEARE_COUNTS. The server sends back a sequence of integers. The number of integers in that list specifies the number of words in each insult; the numbers themselves specify how many possible words there are in each position. So, for example, if you received the output 15 20 30, it would indicate that insults are three words long, with 15 possible...
1. FTP requires confirmation that a file was successfully transmitted to a client, but it has...
1. FTP requires confirmation that a file was successfully transmitted to a client, but it has no built-in mechanism to track this information for itself. What protocol does FTP rely on at the Transport layer of the TCP/IP model to ensure delivery is complete? Group of answer choices UDP HTTP SSH TCP 2. Which of the following tools can be used to determine if a network cable is good? Choose all that apply. Group of answer choices multiple choice Cable...
Socket-based Java server program
Write a Socket-based Java server program that responds to client messages as follows: When it receives a message from a client, it simply converts all the letters into ASCII characters and sends back them to the client. Write both client and server programs demonstrating this.
There are many factors that can influence such decision for cloud server and client server. security,...
There are many factors that can influence such decision for cloud server and client server. security, cost, training and more. which would you choose and why ? there are many factors that influenced the decision on a cloud server or client server such as cost, security, training and more. which one would you choose, cost, security,training etc. and why ? cancel that answer
In Simple Chat, if the server shuts down while a client is connected, the client does...
In Simple Chat, if the server shuts down while a client is connected, the client does not respond, and continues to wait for messages. Modify the client so that it responds to the shutdown of server by printing a message saying the server has shut down, and quitting. (look at the methods called connectionClosed and connectionException). //ChatClient.java // This file contains material supporting section 3.7 of the textbook: // "Object Oriented Software Engineering" and is issued under the open-source //...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT