File Transfer Protocol (FTP) is used to transfer files from one host to another host. Using FTP, files can be shared across computers and can be easily accessed.
The operations performed in FTP are browsing remote FTP site, file upload, file download, file/directory creation, rename, delete etc.
FTP in Java :
Let us see an example to understand the usage of FTP in Java.
Consider a scenario, where your Java application should copy file from the remote server (which has FTP server running) to your locale machine. In this case, we need a FTP client to connect to the remote server using FTP protocol and download the file. How do we get this FTP client embedded in our application? It’s so simple. You can use any of the open source Java FTP libraries to perform the FTP operations. In this tutorial, we are going to use FTP4J library and let’s see how to perform FTP operations, File upload, File download etc.
The User or a program on behalf of the user uses the FTP Client User Interface to execute FTP commands. The FTP User Protocol Interpreter (User PI) interprets the FTP commands and establishes the connection with the FTP Server and exchanges the User commands as per FTP standards. If the FTP command includes file transfer service, then User PI includes the User Data Transfer Process (User DTP) to participate in sending the files.
Upon receiving FTP commands from the User PI, the Server Protocol Interpreter (Server PI) interprets the commands and acknowledges the request with replies. If the request is for file transfer, then the Server PI instructs the Server DTP with the parameters for data transfer and storage so that Server DTP is involved in file transfer with a dedicated connection established between Server DTP and User DTP.