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工具类的更多相关文章

  1. Java基础Map接口+Collections工具类

    1.Map中我们主要讲两个接口 HashMap  与   LinkedHashMap (1)其中LinkedHashMap是有序的  怎么存怎么取出来 我们讲一下Map的增删改查功能: /* * Ma ...

  2. Android—关于自定义对话框的工具类

    开发中有很多地方会用到自定义对话框,为了避免不必要的城府代码,在此总结出一个工具类. 弹出对话框的地方很多,但是都大同小异,不同无非就是提示内容或者图片不同,下面这个类是将提示内容和图片放到了自定义函 ...

  3. [转]Java常用工具类集合

    转自:http://blog.csdn.net/justdb/article/details/8653166 数据库连接工具类——仅仅获得连接对象 ConnDB.java package com.ut ...

  4. js常用工具类.

    一些js的工具类 复制代码 /** * Created by sevennight on 15-1-31. * js常用工具类 */ /** * 方法作用:[格式化时间] * 使用方法 * 示例: * ...

  5. Guava库介绍之实用工具类

    作者:Jack47 转载请保留作者和原文出处 欢迎关注我的微信公众账号程序员杰克,两边的文章会同步,也可以添加我的RSS订阅源. 本文是我写的Google开源的Java编程库Guava系列之一,主要介 ...

  6. Java程序员的日常—— Arrays工具类的使用

    这个类在日常的开发中,还是非常常用的.今天就总结一下Arrays工具类的常用方法.最常用的就是asList,sort,toStream,equals,copyOf了.另外可以深入学习下Arrays的排 ...

  7. .net使用正则表达式校验、匹配字符工具类

    开发程序离不开数据的校验,这里整理了一些数据的校验.匹配的方法: /// <summary> /// 字符(串)验证.匹配工具类 /// </summary> public c ...

  8. WebUtils-网络请求工具类

    网络请求工具类,大幅代码借鉴aplipay. using System; using System.Collections.Generic; using System.IO; using System ...

  9. JAVA 日期格式工具类DateUtil.java

    DateUtil.java package pers.kangxu.datautils.utils; import java.text.SimpleDateFormat; import java.ut ...

随机推荐

  1. WebApp开发技术搭配

    一:Ionic + angular + cordova + zipalign UI框架:lonic+angular 开发与编译打包框架:Cordova 优化工具:zipalign 二:MUI+HBui ...

  2. python pip 安装包报 编码问题

    好久不玩 TF 了, 今天尝试了一个案例,发现要安装module , 就搞了一下, 发现要先安装 base , 安装过程有遇到好多问题, 就写写, 将其中解决过程记录下来. 1. 保存,编码问题 Un ...

  3. lsof详解

    from:https://www.cnblogs.com/the-study-of-linux/p/5501593.html lsof (list open files)是一个列出当前系统打开文件的工 ...

  4. Kettle实现数据抽取、转换、装入和加载数据-数据转移ETL工具

    原文地址:http://www.xue51.com/soft/5341.html Kettle是来自国外的一款开源的ETL工具,纯java编写,可以在Window.Linux.Unix上运行,绿色无需 ...

  5. Nginx Web服务应用

    Nginx 指令目录 Nginx 介绍 Nginx 编译安装 Nginx 功能模块 Nginx 目录结构 Nginx 配置文件 Nginx 虚拟主机配置 Nginx 状态信息功能配置 Nginx 错误 ...

  6. 我的2018:OCR、实习和秋招

    真的是光阴似箭,好像昨天还沉浸在考研成功的喜悦,今天却要即将步入2019年,即将硕士毕业.老规矩,还是在每一年的最后一天总结今年以及展望明年.回首2018,经历的东西特别多,视野也开阔了不少,可以说, ...

  7. 【转载】基于rasa的对话系统搭建(上)

    文章介绍使用rasa nlu和 rasa core 实现一个电信领域对话系统demo,实现简单的业务查询办理功能,更完善的实现需要进一步数据的收集.demo基于玩具数据集,可以达到下面的效果: Bot ...

  8. 【规范】前端编码规范——javascript 规范

    全局命名空间污染与 IIFE 总是将代码包裹成一个 IIFE(Immediately-Invoked Function Expression),用以创建独立隔绝的定义域.这一举措可防止全局命名空间被污 ...

  9. mybatis generator 为数据库保留字段 转义

    为order 添加转义符号“ ` ” `order` <property name="autoDelimitKeywords" value="true"& ...

  10. node踩坑之This is probably not a problem with npm. There is likely additional logging output above.错误

    可能由于种种版本更新的原因需要执行 npm install重新安装一次,如果还是不可以的话,在把之前装的都清空 rm -rf node_modulesrm package-lock.jsonnpm c ...