详细使用方法
依赖库
```
<!-- ftpclient -->
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.4.2</version>
</dependency>
```
已经编译后的库
https://gitee.com/lliaoliao/ftppool/raw/master/bin/ftppool-1.0.jar
FTPPool 类里面有详细的调用情况
eg
```
public static void main(String[] args) throws Exception {
FTPPoolConfig config = new FTPPoolConfig() ;
config.setHost("192.168.1.20");
config.setPort(21);
config.setUsername("elen");
config.setPassword("Elen@123");
config.setPassiveMode("true");
config.setClientTimeout(300000);
config.setTransferFileType(2);
//config.setMaxTotal(10);
config.setMaxIdle(5);
config.setMinIdle(1);
config.setTestOnBorrow(true);
config.setTestOnReturn(true);
config.setTestWhileIdle(true);
config.setNumTestsPerEvictionRun(10);
config.setTimeBetweenEvictionRunsMillis(60000);
FTPClientFactory f = new FTPClientFactory() ;
f.setConfig(config);
final FTPPool pool = new FTPPool(config, f) ;
for(int i = 20 ;i>0 ; i--){
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
FTPClient ftp = pool.getPool().borrowObject() ;
System.out.println(Thread.currentThread().getName()+"--获得一个");
Thread.sleep(60000);
pool.getPool().returnObject(ftp);
System.out.println(Thread.currentThread().getName()+"取消一个");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
},"name--"+i) ;
t.start();
}
System.out.println("执行完毕");
Thread.sleep(60000*20);
}
```
spring 调用方式
```
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd"
default-autowire="byName">
<bean id="ftpConfig" class="com.hatchsolution.ftp.pool.FTPPoolConfig" >
<property name="host" value="192.168.1.20"/>
<property name="port" value="21"/>
<property name="username" value="elen"/>
<property name="password" value="Elen@123"/>
<property name="passiveMode" value="true"/>
<property name="clientTimeout" value="300000"/>
<property name="transferFileType" value="2"/>
<property name="maxTotal" value="10"/>
<property name="maxIdle" value="5"/>
<property name="minIdle" value="2"/>
<property name="testOnBorrow" value="true"/>
<property name="testOnReturn" value="true"/>
<property name="testWhileIdle" value="true"/>
<property name="numTestsPerEvictionRun" value="10"/>
<property name="timeBetweenEvictionRunsMillis" value="60000"/>
</bean>
<bean id="ftpClientFactory" class="com.hatchsolution.ftp.factory.FTPClientFactory" >
<constructor-arg name="config" ref="ftpConfig"></constructor-arg>
</bean>
<bean id = "ftpPool" class="com.hatchsolution.ftp.pool.impl.FTPPool" scope="singleton">
<constructor-arg name="factory" ref="ftpClientFactory"></constructor-arg>
</bean>
<bean id = "ftpUtils" class="com.hatchsolution.ftp.FTPUtils" scope="singleton">
<property name="pools" ref="ftpPool"/>
</bean>
</beans>
```
软件主页 | https://gitee.com/lliaoliao/ftppool.git |
---|---|
文档地址 | https://gitee.com/lliaoliao/ftppool.wiki.git |
下载地址 | https://gitee.com/lliaoliao/ftppool/repository/archive/master.zip |
授权协议 | GPL LGPL AGPL Apache MIT BSD EPL MPL 其它 |
本链接池由济南汉驰信息科技有限公司编写本着开源原则欢迎探讨。