FTPService工具类
package com.vcredit.ddcash.server.commons.net;
import com.vcredit.ddcash.server.commons.model.FtpParam;
import org.apache.commons.net.ftp.*;
import org.apache.commons.net.ftp.parser.MLSxEntryParser;
import org.apache.commons.net.io.*;
import org.apache.commons.net.io.SocketOutputStream;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.io.*;
import java.net.*;
import java.nio.charset.Charset;
import java.util.ArrayList;
/**
* Created by guanshuli on 2017/2/7.
*/
@Component
public class FTPService {
private static final Logger logger = Logger.getLogger(FTPService.class);
@Value("${identity.disk.save.path}")
private String identityPath;
@Value("${identity.ftp.userName}")
private String userName;
@Value("${identity.ftp.password}")
private String password;
@Value("${identity.ftp.server}")
private String hostname;
@Value("${identity.ftp.port}")
private int port;
public String __systemName;
public boolean __autodetectEncoding = false;
public int __dataConnectionMode;
public int __fileType;
public boolean __remoteVerificationEnabled;
public int __controlKeepAliveReplyTimeout = 1000;
public long __controlKeepAliveTimeout;
public int __fileFormat;
public int __bufferSize;
public CopyStreamListener __copyStreamListener;
public int receiveBufferSize = -1;
public int sendBufferSize = -1;
public boolean connect(FTPClient ftpClient) throws IOException {
if (!ftpClient.isConnected()) {
ftpClient.connect(hostname, port);
}
ftpClient.setConnectTimeout(50000);
return ftpClient.login(userName, password);
}
public void connect(FTPClient ftpClient,String hostname, int port) throws IOException {
ftpClient.connect(InetAddress.getByName(hostname), port);
}
public void connect(FTPClient ftpClient,String hostname, int port, String userName, String password) throws IOException {
ftpClient.setConnectTimeout(50000);
ftpClient.connect(hostname, port);
ftpClient.login(userName, password);
}
static String __parsePathname(String reply) {
String param = reply.substring(4);
if (param.startsWith("\"")) {
StringBuilder sb = new StringBuilder();
boolean quoteSeen = false;
for (int i = 1; i < param.length(); ++i) {
char ch = param.charAt(i);
if (ch == 34) {
if (quoteSeen) {
sb.append(ch);
quoteSeen = false;
} else {
quoteSeen = true;
}
} else {
if (quoteSeen) {
return sb.toString();
}
sb.append(ch);
}
}
if (quoteSeen) {
return sb.toString();
}
}
return param;
}
public void closeFtpClient(FTPClient ftpClient) throws IOException {
if (ftpClient.isConnected()) {
ftpClient.disconnect();
}
}
public boolean exists(FTPClient ftpClient,String fileName) throws IOException {
return ftpClient.exists(fileName);
}
public boolean uploadImg(FTPClient ftpClient,String diskSavePath, FtpParam param, InputStream inputStream) throws IOException {
return ftpClient.uploadImg(diskSavePath, param, inputStream);
}
public boolean rename(FTPClient ftpClient,String from, String to) throws IOException {
return ftpClient.rename(from, to);
}
public boolean deleteFile(FTPClient ftpClient,String file) throws IOException {
return ftpClient.deleteFile(file);
}
public FTPFile[] listFiles(FTPClient ftpClient,String rootPath) throws IOException {
return ftpClient.listFiles(rootPath);
}
public boolean isFile(FTPClient ftpClient,String file) throws IOException {
return ftpClient.isFile(file);
}
public boolean setFileType(FTPClient ftpClient,int fileType) throws IOException {
return ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
}
public boolean setFileTransferMode(FTPClient ftpClient,int fileType) throws IOException {
return ftpClient.setFileTransferMode(fileType);
}
public void setControlEncoding(FTPClient ftpClient,String charset) throws IOException {
ftpClient.setControlEncoding(charset);
}
public InputStream retrieveFileStream(FTPClient ftpClient,String fileName) throws IOException {
return ftpClient.retrieveFileStream(fileName);
}
public boolean retrieveFileStream(FTPClient ftpClient,String remote, OutputStream local) throws IOException {
return ftpClient.retrieveFile(remote, local);
}
public void removeDirectory(FTPClient ftpClient,String parentDir,
String currentDir) throws IOException {
ftpClient.removeDirectory(parentDir, currentDir);
}
public long mdtm(FTPClient ftpClient,String fileName) throws IOException {
return ftpClient.mdtm(fileName);
}
}
FTPService工具类的更多相关文章
- Java基础Map接口+Collections工具类
1.Map中我们主要讲两个接口 HashMap 与 LinkedHashMap (1)其中LinkedHashMap是有序的 怎么存怎么取出来 我们讲一下Map的增删改查功能: /* * Ma ...
- Android—关于自定义对话框的工具类
开发中有很多地方会用到自定义对话框,为了避免不必要的城府代码,在此总结出一个工具类. 弹出对话框的地方很多,但是都大同小异,不同无非就是提示内容或者图片不同,下面这个类是将提示内容和图片放到了自定义函 ...
- [转]Java常用工具类集合
转自:http://blog.csdn.net/justdb/article/details/8653166 数据库连接工具类——仅仅获得连接对象 ConnDB.java package com.ut ...
- js常用工具类.
一些js的工具类 复制代码 /** * Created by sevennight on 15-1-31. * js常用工具类 */ /** * 方法作用:[格式化时间] * 使用方法 * 示例: * ...
- Guava库介绍之实用工具类
作者:Jack47 转载请保留作者和原文出处 欢迎关注我的微信公众账号程序员杰克,两边的文章会同步,也可以添加我的RSS订阅源. 本文是我写的Google开源的Java编程库Guava系列之一,主要介 ...
- Java程序员的日常—— Arrays工具类的使用
这个类在日常的开发中,还是非常常用的.今天就总结一下Arrays工具类的常用方法.最常用的就是asList,sort,toStream,equals,copyOf了.另外可以深入学习下Arrays的排 ...
- .net使用正则表达式校验、匹配字符工具类
开发程序离不开数据的校验,这里整理了一些数据的校验.匹配的方法: /// <summary> /// 字符(串)验证.匹配工具类 /// </summary> public c ...
- WebUtils-网络请求工具类
网络请求工具类,大幅代码借鉴aplipay. using System; using System.Collections.Generic; using System.IO; using System ...
- JAVA 日期格式工具类DateUtil.java
DateUtil.java package pers.kangxu.datautils.utils; import java.text.SimpleDateFormat; import java.ut ...
随机推荐
- Javascript 函数声明、函数表达式与匿名函数自执行表达式
函数表达式(Function Expression)注:将函数定义为表达式语句(通常是变量赋值)的一部分 //func() 错误 var func = function () { } //func() ...
- [转]PID控制算法原理
PID控制算法是工业界使用极其广泛的一个负反馈算法,相信这个算法在做系统软件时也有用武之处,这里摘录了知乎上的一篇文章,后面学习更多后自己总结一篇 以下为原文: PID控制应该算是应用非常广泛的控制算 ...
- VMWare 虚机迁移后Linux系统网卡启动问题
重新安装VMWare或拷贝虚机文件后有时网卡会无法工作,主要是因为网卡的Mac地址改变了,如果系统中的网卡配置信息中有Mac的信息,则虚机的系统的网卡可能无法正常工作. 如果出现上述问题,解决办法如下 ...
- C#做单元测试,如何查看输出的调试信息?
- 程序运行在.Net 4.0低版本上 报“System.NullReferenceException”错误
因为程序仅在个别机器上出现“ System.NullReferenceException”问题,而在其他机器上一切运行正常,所以认为是环境问题 具体错误信息如下: 2018-09-14 10:12:1 ...
- Python的数据库mongoDB的入门操作
Python代码: import pymongo # 获取本地端口,激活mongo客户端 client = pymongo.MongoClient('localhost',27017) # 创建一个数 ...
- mysql 动态增加列,查找表中有多少列,具体什么列。 通过JSON生成mysql表 支持子JSON
好消息, 程序员专用早餐机.和掌柜说 ideaam,可以节省20元. 点击链接 或復·制这段描述¥k3MbbVKccMU¥后到淘♂寳♀ 或者 淘宝扫码 支持下同行哈 ---------------- ...
- mschart asp chart 用法,包括前台写法与后台写法,还有click事件,如何触发。
纯后台动态生成aspchart ,这种方式没办法实现chart中click事件.click事件点击没有反应,用第二种可以实现点击事件. 两种方式实现同一种效果图: 第一种写法:后台动态生成aspcha ...
- atitit 读书与获取知识资料的attilax的总结.docx
atitit 读书与获取知识资料的attilax的总结.docx 1.1. 读书即是获取知识,获取资料,获取信息的一种方式 2 2. 获取资料信息的目的,有什么作用,有什么用途?? 2 2.1. 扩大 ...
- Cocos 更新时反复杀进程,导致差异更新失效的Bug
Cocos 更新时反复杀进程时,差异更新失效的问题: 问题复现步骤: 1.在project.manifest.temp 文件下载成功后,下载Assets资源的时候杀掉进程 2.重启游戏,继续更新时会使 ...