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. grid - 网格项目层级

    网格项目可以具有层级和堆栈,必要时可能通过z-index属性来指定. 1.在这个例子中,item1和item2的开始行都是1,item1列的开始是1,item2列的开始是2,并且它们都跨越两列.两个网 ...

  2. ionic 视图滚动到顶部

    问题描述 进入页面, 滚动到底部 点击一个连接, 当前视图内容更新了 内容滚动到了上次的位置导致底部的内容没显示 需要控制自动回滚到顶部 <ion-content delegate-handle ...

  3. protobuf 动态创建

    https://www.ibm.com/developerworks/cn/linux/l-cn-gpb/index.html https://originlee.com/2015/03/14/ana ...

  4. vue: 代码小记

    1.事件派发:子控件->父控件 <!DOCTYPE html> <html> <head> <meta charset="UTF-8" ...

  5. 树莓派进阶之路 (038) - P2P 文件下载机

    硬件要求: 树莓派开发板 USB外接硬盘 一. Together 1. 更新安装程序 sudo apt-get update sudo apt-get upgrade sudo apt-get ins ...

  6. Linux驱动面试题

    1. Linux设备中字符设备与块设备有什么主要的区别?请分别列举一些实际的设备说出它们是属于哪一类设备. 字符设备:字符设备是个能够像字节流(类似文件)一样被访问的设备,由字符设备驱动程序来实现这种 ...

  7. Gradle 离线 安装

    第一步:下载gradle zip 文件 第二步:打开文件夹,例如:C:\Users\Administrator.gradle\wrapper\dists\gradle-3.3-all\55gk2rcm ...

  8. matplotlib绘图不显示问题解决plt.show()

    最近在看<Python数据分析>这本书,而自己写代码一直用的是Pycharm,在练习的时候就碰到了plot()绘图不能显示出来的问题.网上翻了一下找到知乎上一篇回答,试了一下好像不行,而且 ...

  9. C语言 · 猜算式 · 乘法竖式

    题目:猜算式 你一定还记得小学学习过的乘法计算过程,比如: 273 x   15 ------ 1365 273 ------ 4095 请你观察如下的乘法算式 *** x   *** ------- ...

  10. js 可拖动div 调整大小

    dragBorder: function (parent, right, bottom, bottomRight) { var isDownRight = false; var isDownBotto ...