Apache ftpserver整合springboot

简介: Springboot集成ftpserver,添加用户

Apache ftpserver集成


Apache ftpserver由Java语言开发的Ftp服务器,集成到其它程序,正常运行需要:

  • mina-core, 2.0-M3 or later
  • slf4j-api
  • A SLF4J implementation of your choice, for example slf4j-simple-1.5.3.jar
  • ftplet-api
  • ftpserver-core
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.7.25 </version>
</dependency>
<dependency>
    <groupId>org.apache.ftpserver</groupId>
    <artifactId>ftpserver-core</artifactId>
    <version>1.1.1</version>
</dependency>
<dependency>
    <groupId>org.apache.ftpserver</groupId>
    <artifactId>ftplet-api</artifactId>
    <version>1.1.1</version>
</dependency>
<dependency>
    <groupId>org.apache.mina</groupId>
    <artifactId>mina-core</artifactId>
    <version>2.0.16</version>
</dependency>

Springboot应用集成 Apache ftpserver


_1

代码


@Configuration
public class FtpConfig {
    private final Logger logger = LoggerFactory.getLogger(FtpConfig.class);

    @Bean
    public UserManager getUserManger() throws FtpException {

        FtpServerFactory serverFactory = new FtpServerFactory();
        
        // ftp服务监听的端口号
        ListenerFactory factory = new ListenerFactory();
        factory.setPort(2221);
        serverFactory.addListener("default", factory.createListener());
        
        // 创建用户
        BaseUser user = new BaseUser();
        user.setName("admin");
        user.setPassword("123456");
        user.setHomeDirectory("E:\\FTPServerPath");

        List<Authority> authorities = new ArrayList<Authority>();
        authorities.add(new WritePermission());
        user.setAuthorities(authorities);
        UserManager userManager = serverFactory.getUserManager();
        userManager.save(user);
      
           serverFactory.setUserManager(userManager);
        
        FtpServer server = serverFactory.createServer();
        server.start();
        logger.info("ftp已经启动!");
 
        return userManager;
    }
}

@Component
public class SpringUtil implements ApplicationContextAware {
 
    private static ApplicationContext applicationContext;
 
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        
        if(SpringUtil.applicationContext == null) {
            SpringUtil.applicationContext = applicationContext;
        }
    }
     
    //SpringUtils.getApplicationContext()获取applicationContext对象
    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }
     
    public static Object getBean(String name){
        return getApplicationContext().getBean(name);
    }
 
    public static <T> T getBean(Class<T> clazz){
        return getApplicationContext().getBean(clazz);
    }
 
    public static <T> T getBean(String name,Class<T> clazz){
        return getApplicationContext().getBean(name, clazz);
    }
 
}
相关文章
|
7月前
|
Java 程序员 API
Springboot-swagger配置(idea社区版2023.1.4+apache-maven-3.9.3-bin)
Springboot-swagger配置(idea社区版2023.1.4+apache-maven-3.9.3-bin)
185 1
|
7月前
|
前端开发 Java 数据库连接
Springboot-MyBatis配置-配置端口号与服务路径(idea社区版2023.1.4+apache-maven-3.9.3-bin)
Springboot-MyBatis配置-配置端口号与服务路径(idea社区版2023.1.4+apache-maven-3.9.3-bin)
83 0
|
7月前
|
Java
SpringBoot启动报错:org.apache.catalina.LifecycleException: Protocol handler start failed
SpringBoot启动报错:org.apache.catalina.LifecycleException: Protocol handler start failed
106 0
|
20天前
|
消息中间件 Java Kafka
什么是Apache Kafka?如何将其与Spring Boot集成?
什么是Apache Kafka?如何将其与Spring Boot集成?
53 5
|
23天前
|
消息中间件 Java Kafka
Spring Boot 与 Apache Kafka 集成详解:构建高效消息驱动应用
Spring Boot 与 Apache Kafka 集成详解:构建高效消息驱动应用
36 1
|
7月前
|
Java
SpringBoot启动报错org.apache.catalina.LifecycleException
SpringBoot启动报错org.apache.catalina.LifecycleException
55 0
|
4月前
|
Java Maven Spring
SpringBoot 系列之 Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resource
这篇文章描述了在使用Maven构建Spring Boot项目时遇到的`maven-resources-plugin`插件版本问题导致的编译失败,并提供了通过修改插件版本至3.1.0来解决这个问题的方法。
SpringBoot 系列之 Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resource
|
4月前
|
消息中间件 Java Kafka
|
7月前
|
Java
springboot打包错误:Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resource
springboot打包错误:Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resource
95 0
|
4月前
|
Java Spring Apache
Spring Boot邂逅Apache Wicket:一次意想不到的完美邂逅,竟让Web开发变得如此简单?
【8月更文挑战第31天】Apache Wicket与Spring Boot的集成提供了近乎无缝的开发体验。Wicket以其简洁的API和强大的组件化设计著称,而Spring Boot则以开箱即用的便捷性赢得开发者青睐。本文将指导你如何在Spring Boot项目中引入Wicket,通过简单的步骤完成集成配置。首先,创建一个新的Spring Boot项目并在`pom.xml`中添加Wicket相关依赖。
130 0

推荐镜像

更多
下一篇
DataWorks