filezilla is a ftp client written in java inspired by the popular http client okhttp. It uses the builder design pattern to easily construct a path on the server or the configuration of a session. In the core it uses the apache commons net ftp client and wraps the methods in a simple and clean API. Currently it only supports ftp, but in the future it will support ftps and sftp.
To use the FilezillaManager, you only have to add the artifact to your dependencies section inside your pom.xml and then you are ready to go.
<dependency>
<groupId>com.dardan.rrafshi</groupId>
<artifactId>filezilla</artifactId>
<version>1.0.0</version>
</dependency>To create a FilezillaManager object you need to specify the session data first. Therefore you have to a FilezillaSession object. Then you can use the use the methods to operate CRUDL operations on files and folders on the file server. The default file type for a session is FileType.BINARY and the default transfer mode is FileTransferMode.STREAM.
finalFilezillaSessionsession = FilezillaSession.builder()
.login(Constants.DEFAULT_FTP_USERNAME, Passwords.getPasswordFromFile("filezilla"))
.fileType(FileType.ASCII)
.transferMode(FileTransferMode.COMPRESSED)
.build();
FilezillaManagerfilezillaManager = newFilezillaManager(session);try(FilezillaManagerfilezillaManager = newFilezillaManager(session)) {
// Download a fileFilezillaPathoriginPath = FilezillaPath.parse("/artists/all time low/future hearts/Something's Gotta Give.mp3");
PathtargetPath = Paths.get("C:\\Users\\{username}\\Music\\Temp\\Something's Gotta Give.mp3");
filezillaManager.downloadFile(originPath, targetPath);
// Download a folderoriginPath = FilezillaPath.parse("/artists/all time low");
targetPath = Paths.get("C:\\Users\\drraf\\Music\\Temp\\");
filezillaManager.downloadFolder(originPath, targetPath);
}try(FilezillaManagerfilezillaManager = newFilezillaManager(session)) {
// Upload a filePathoriginPath = Paths.get("C:\\Users\\{username}\\Music\\Artists\\All Time Low\\Future Hearts\\Something's Gotta Give.mp3");
FilezillaPathtargetPath = FilezillaPath.parse("/artists/all time low/future hearts");
filezillaManager.uploadFile(originPath, targetPath);
// Upload a folderoriginPath = Paths.get("C:\\Users\\drraf\\Music\\Temp\\all time low");
targetPath = FilezillaPath.parse("/artists");
filezillaManager.uploadFolder(originPath, targetPath);
}