AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Download ftp server12/19/2023 FTPDownloadDirectoryTest.javaRun the program: Javac -cp commons-net-VERSION.jar FTPUtil.javaCompile the test program: log out and disconnect from the server String saveDirPath = "E:/Test/Download/FTP" įTPUtil.downloadDirectory(ftpClient, remoteDirPath, "", saveDirPath) use local passive mode to pass firewall Now we create a test program as follows: import java.io.IOException Only the recursive calls will pass specific values for this parameter. directory where the files will be savedįTPUtil.downloadDirectory(ftpClient, remoteDirPath, "", saveDirPath) Notice that we always pass an empty String (“”) for the parameter currentDir when calling this method. directory on the server to be downloaded The following example illustrates how to use this method: FTPClient ftpClient = new FTPClient() The important point in this method is to re-create directory structure of the remote directory on the local computer correctly. Repeat the same steps for the sub directory, and sub directory of sub directory, and so on (recursively). If the current item is a directory, create that directory in the local computer and call the downloadDirectory() method itself.If the current item is a file, call the method downloadSingleFile() to download that file.List files and directories recursively on a FTP server.įor the sake of reusability, we implement the solution as a utility class looks like this: public class FTPUtil This method iterates over all files and sub directories of the current directory in the following manner:.In this article, we present a solution for downloading a whole directory from the FTP server, which is tested and proved as working very well.The solution is based on these two tutorials: However it would be quite complex if we want to download a complete directory because a directory differs greatly from a file, as it may contain sub files and sub directories which can be nested in many levels. It’s not difficult to write Java code for downloading a single file from a FTP server.
0 Comments
Read More
Leave a Reply. |