java ftpclient 池_GitHub - jellyflu/ftpClientPool: 此ftp客户端连接池底层依赖apache的commons-net和commons-pool2,基于这...

ftpClientPool

此ftp客户端连接池底层依赖apache的commons-net和commons-pool2,基于这二者做的个薄层封装,让我们在spring项目中以更简洁、高效的方式使用ftpClient

如何使用

1、下载jar包 ftpClientPool-xx.jar(我用maven编译好的jar包)到你的工程lib中,或者下载此项目源码后在本地编译亦可。

2、在你的spring主配置文件中引入spring-ftpClientPool.xml配置文件

示例如下:

spring-ftpClientPool.xml 配置如下:

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:aop="http://www.springframework.org/schema/aop"

xmlns:tx="http://www.springframework.org/schema/tx"

xmlns:cache="http://www.springframework.org/schema/cache"

xsi:schemaLocation="

http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-4.3.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context-4.3.xsd

http://www.springframework.org/schema/aop

http://www.springframework.org/schema/aop/spring-aop-4.3.xsd

http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx-4.3.xsd

http://www.springframework.org/schema/cache

http://www.springframework.org/schema/cache/spring-cache-4.3.xsd">

3、在你的 spring主配置文件中新载入一个ftpPoolConfig.properties配置

示例如下:

classpath:jdbc.properties

classpath:redis.properties

classpath:ftpPoolConfig.properties

4、在你的工程classpath中新加ftpPoolConfig.properties属性配置文件

示例:

ftp.host=127.0.0.1

ftp.port=21

ftp.username=ftptest

ftp.password=123456

#ftp 连接超时时间 毫秒

ftp.connectTimeOut=5000

#控制连接 字符编码

ftp.controlEncoding=UTF-8

#缓冲区大小

ftp.bufferSize=1024

#传输文件类型 2表二进制

ftp.fileType=2

#数据传输超时 毫秒

ftp.dataTimeout=120000

#

ftp.useEPSVwithIPv4=false

#是否启用ftp被动模式

ftp.passiveMode=true

#连接耗尽时是否阻塞, false报异常,ture阻塞直到超时, 默认true

ftp.blockWhenExhausted=true

#最大空闲等待时间 毫秒

ftp.maxWaitMillis=3000

#最大连接数

ftp.maxTotal=10

#最大空闲连接数

ftp.maxIdle=10

#最小空闲连接数

ftp.minIdle=2

#申请连接时 检测是否有效

ftp.testOnBorrow=true

#返回连接时 检测是否有效

ftp.testOnReturn=true

#创建连接时 检测是否有效

ftp.testOnCreate=true

#空闲时检测连接是否有效

ftp.testWhileIdle=true

5、在你的spring工程中如何使用此模块(ftpClientPool)

示例1:

@Resource

private FTPClientHelper ftpClientHelper ;// 注入ftp客户端helper对象使用

示例2:

@Resource

private FTPClientPool ftpClientPool;// 注入 ftp客户端连接池对象使用

示例3: 你也可以同时注入上面二者

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值