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. Keras运行速度越来越慢的问题

    Keras运行迭代一定代数以后,速度越来越慢,经检查是因为在循环迭代过程中增加了新的计算节点,导致计算节点越来越多,内存被占用完,速度变慢.判断是否在循环迭代过程中增加了新的计算节点,可以用下面的语句 ...

  2. 每天一个linux命令:df

    1.命令简介 df (disk free) 其功能显示每个文件所在的文件系统的信息,默认是显示所有文件系统. 2.用法 df [选项]... [文件]... 3.选项   4.示例 示例1:显示磁盘使 ...

  3. 【Python】 解析Python中的运算符

    Python中的运算符相比较于传统的C/C++差别不是很大,主要是一些个别的运算符上的差别.包括:算术.比较.赋值.位.逻辑.成员.身份等.它们的优先级: 符号 说明 ** 指数(最高优先级) ~,+ ...

  4. Atitit.如何文章写好 论文 文章 如何写好论文 技术博客

    Atitit.如何文章写好 论文  文章  如何写好论文 技术博客 1. 原则 1 1.1. 有深度, 有广度 1 1.2. 业务通用性有通用性 尽可能向上抽象一俩层..业务通用性与语言通用性. 2 ...

  5. pandas DataFrame(5)-合并DataFrame与Series

    之前已经学过DataFrame与DataFrame相加,Series与Series相加,这篇介绍下DataFrame与Series的相加: import pandas as pd s = pd.Ser ...

  6. postMessage使用方法

    1.子页面向父页面发送消息 var parentData = {type: 'passDataBack', data: passData}; window.parent.postMessage(par ...

  7. 强化学习-时序差分算法(TD)和SARAS法

    1. 前言 我们前面介绍了第一个Model Free的模型蒙特卡洛算法.蒙特卡罗法在估计价值时使用了完整序列的长期回报.而且蒙特卡洛法有较大的方差,模型不是很稳定.本节我们介绍时序差分法,时序差分法不 ...

  8. 详解Zookeeper原理与应用场景

    Zookeeper 分布式协调服务 应用之处:发布.订阅,命名服务,分布式协调和分布式锁 对比 Chubby: Chubby 被定义为 分布式的锁服务 为分布式系统提供 松耦合.粗粒度 的分布式锁功能 ...

  9. [转]剑指offer之Java源代码

    一.引言 <剑指offer>可谓是程序猿面试的神书了,在面试中帮了我很多,大部分面试的算法题都会遇到原题或者是类似的题.但是书上的代码都是C版的,我在这里整理了一份Java版的代码供大家学 ...

  10. GLSL版本的区别和对比

    之前尝试将一个GLSL version 110的版本写成GLSL version 330的,在此将学习过程和收获记录下来. 参考链接 GLSL Versions 介绍 你可以使用#version命令作 ...