<dependency> <groupId>org.fabric3</groupId> <artifactId>fabric3-ftp-spi</artifactId> <version>1.0.0</version> </dependency> <configuration> <ftp:connections> <ftp:connection name="myFtpConnection" host="ftp.example.com" port="21" username="myusername" password="mypassword"/> </ftp:connections> </configuration> public interface FtpService { void uploadFile(String connectionName, String remotePath, String localPath); void downloadFile(String connectionName, String remotePath, String localPath); void deleteFile(String connectionName, String remotePath); } public class FtpServiceImpl implements FtpService { private FtpConnectionFactory factory; public FtpServiceImpl(FtpConnectionFactory factory) { this.factory = factory; } public void uploadFile(String connectionName, String remotePath, String localPath) { try (FtpConnection connection = factory.createConnection(connectionName)) { connection.upload(remotePath, new File(localPath)); } catch (FtpException e) { } } public void downloadFile(String connectionName, String remotePath, String localPath) { try (FtpConnection connection = factory.createConnection(connectionName)) { connection.download(remotePath, new File(localPath)); } catch (FtpException e) { } } public void deleteFile(String connectionName, String remotePath) { try (FtpConnection connection = factory.createConnection(connectionName)) { connection.delete(remotePath); } catch (FtpException e) { } } }


上一篇:
下一篇:
切换中文