![Org.apache.commons.net.ftp. ftpclient jar](https://kumkoniak.com/69.jpg)
![org.apache.commons.net.ftp. ftpclient jar org.apache.commons.net.ftp. ftpclient jar](https://www.thaicreate.com/upload/tutorial/java-ftp-upload-04.jpg)
In addition, the following two methods must be invoked before calling the retrieveFile() and retrieveFileStream()methods: Therefore, make sure to handle these exceptions when calling the methods. O Both the methods throw an IOException exception (or one of its descendants, FTPConnectionClosedException andCopyStreamException). In addition, we have to call thecompletePendingCommand()to finalize the download. how many percentages of the file have been transferred. O The second method requires more code to be written, as we have to create a new OutputStream for writing file’s content while reading its byte arrays from the returned InputStream.This method is useful when we want to measure progress of the download, i.e. O The first method provides the simplest way for downloading a remote file, as just passing an OutputStream of the file will be written on disk. Which method is used suitable for you? Here are few tips:  We must close the InputStream explicitly.  The method completePendingCommand() must be called afterward to finalize file transfer and check its return value to verify if the download is actually done successfully. But there are two important points when using this method: This method gives us more control on how to read and write the data.
![org.apache.commons.net.ftp. ftpclient jar org.apache.commons.net.ftp. ftpclient jar](https://i.stack.imgur.com/apCAU.png)
O InputStream retrieveFileStream(String remote): This method does not use an OutputStream, instead it returns an InputStreamwhich we can use to read bytes from the remote file. We should close OutputStream the after the method returns. This method is suitable in case we don’t care how the file is written to disk, just let the system use the given OutputStream to write the file. The method returns true if operation completed successfully, or false otherwise. O boolean retrieveFile(String remote, OutputStream local): This method retrieves a remote file whose path is specified by the parameter remote, and writes it to the OutputStream specified by the parameter local. The .ftp.FTPClient class provides two methods for downloading files from a FTP server: Apache Commons Net API for downloading files by FTP protocol A working sample program also provided.ġ. In this article, you will learn how to properly implement Java code to get files downloaded from a server via FTP protocol.
![org.apache.commons.net.ftp. ftpclient jar org.apache.commons.net.ftp. ftpclient jar](https://www.driverlandia.com/wp-content/uploads/2019/05/eclipse-configure-build-path.png)
With the help of Apache Commons Net API, it is easy to write Java code for downloading a file from a remote FTP server to local computer. Java FTP file download tutorial and example Article : Java FTP file download tutorial and example
![Org.apache.commons.net.ftp. ftpclient jar](https://kumkoniak.com/69.jpg)