00:01
In this question, we have to write a code in java that will provide us a basic structure for an ftp client in java.
00:12
So we have to provide a basic structure for ftp client in java.
00:34
So here we have to establish a connection with the server that reads command from the user then sends the corresponding ftp commands to the server that is there and then displays the server's response.
00:51
However, it does not handle all the possible error cases or implement all the required commands fully.
00:58
So we will have to extend and refine it to meet the requirements of a project.
01:05
Then we have to note that in this implementation, it does not provide a graphical user interface.
01:12
So we have to see that it does not the graphical user interface that is there that is gui.
01:27
But it rather than the gui, it rather gives a simple line interface that is gives a simple command command line interface that is cli.
01:56
So adding a gui to the ftp client is beyond the scope in this example.
02:05
But we can consider using a gui framework like swing.
02:09
So we can use a gui framework like swing and or that or there is also javafx.
02:30
So to build a graphical interface around the provided functionality that is there.
02:41
So we'll see how this is done in java basic compiler.
02:48
So let us look at the code that i'll explain you.
02:51
So the first thing that we are going to start with is importing the basic necessary files that are there that is the header files in java.
03:03
So we import these.
03:04
So next step we will do is we will define a public class that is ftp.
03:11
So i'll just write that here.
03:15
So what we have done is we have defined constants for the ftp port here that is ftp for the ftp client i mean and that is for f that they are ftp port that is 21 and the buffer size that is 1024.
03:33
These are used for data transfers.
03:37
The ftp client class now is defined which will contain the main logic of the ftp client.
03:45
So now we have to start a main method so that the program checks if the command lines argument are provided correctly.
03:54
If not the usage message and it will display the usage message and it will return.
04:02
So we have to give these also along with that.
04:10
So we will be using all these later on and we will start a main method that will start the main check if the command line arguments are provided or not.
04:25
So for that we will be starting with this.
04:29
So here as you can see we have included something as the connect method.
04:38
So this connect method is responsible for establishing a connection with the ftp server.
04:45
So it creates the socket and initializes the input and output streams and then it will display the users or servers welcome message.
04:56
So now we will use a start method furthermore.
05:01
So we will first further give the connect method properly like this.
05:07
So it will read all these and as i told you it is responsible for establishing a connection with the ftp servers here.
05:18
So it will create all these socket reader, writer, scanner for the input and output streams.
05:25
So next thing we have to do is we have to start a start method that contains the main loop of the ftp client.
05:33
So let us see that we have we will write a start method here.
05:41
So here as you can see this will contain the main loop and it prompts the user for commands then it will parse them and execute the corresponding ftp commands based on the input.
05:55
So now inside this loop the users input will be split into command parts using white space as a delimiter and the first part is extracted as the cmd as you can see and it is converted to lowercase for easier comparison.
06:15
So that is why we have written strings cmd to lowercase so that it will be easier for us to compare.
06:23
So now we will be starting with a switch statement that the code handles each supported command.
06:31
So for that we have several commands that we will be using and i'll be explaining them one by one...