惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
D
DataBreaches.Net
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
Docker
N
Netflix TechBlog - Medium
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
Check Point Blog
腾讯CDC
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
IT之家
IT之家
月光博客
月光博客
U
Unit 42
K
Kaspersky official blog
T
Threatpost
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
GbyAI
GbyAI
P
Proofpoint News Feed
Last Week in AI
Last Week in AI
云风的 BLOG
云风的 BLOG
酷 壳 – CoolShell
酷 壳 – CoolShell
I
InfoQ
Engineering at Meta
Engineering at Meta
Recorded Future
Recorded Future
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Security @ Cisco Blogs
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
Security Archives - TechRepublic
Security Archives - TechRepublic
Webroot Blog
Webroot Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
S
Schneier on Security
S
Secure Thoughts
The Register - Security
The Register - Security
B
Blog RSS Feed
The Last Watchdog
The Last Watchdog
P
Palo Alto Networks Blog
爱范儿
爱范儿
B
Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
L
LINUX DO - 热门话题
C
Cisco Blogs
Spread Privacy
Spread Privacy
F
Full Disclosure
博客园 - 聂微东
T
The Blog of Author Tim Ferriss

博客园 - cndavy

如何在WINDOW环境下搭建ActivateMQ和zookeeper集群环境 Esp8266 例子 树莓派 安装 docker CSV 文件处理成 String[] ,网银下载的文本中使用逗号分割, 使用双引号标记字段. 使用String split 会出现把引号中的逗号识别的情况 例如 " ,,,, " , "aaa" 切换网卡的脚本 apache xampp 目录防止解析php WordPress搬家教程:换空间与换域名 sympy 的 符号计算的例子 Conda 简单使用 spoolsv.exe 无法启动 太阳高度角和方位角的计算 树莓派 3 alsa 声卡驱动 PHP 7 Xdebug 深深的坑 java 线性规划 和lingo 比较 Cannot find or open the PDB file问题的解决 Python Microsoft Visual C++ Compiler Package for Python 2.7 Node debug angular 调试 js (分 karms protractor / test e2e unit ) hbase scan 的例子
FTPS 客户端 demo,
cndavy · 2017-08-30 · via 博客园 - cndavy

package han; import java.util.Vector; /** * Created by han on 2017/8/30. */ public class FtpTest { private static FtpClient ftpClient; public static void main (String[] args) throws Exception { ftpClient =new FtpClient( true); ftpClient.connect("127.0.0.1","a","a",990); ftpClient.getWorkingDirectory(); ftpClient.changeDir("/"); Vector<String> dirs= ftpClient.listSubDirInDir("/"); for (String dir :dirs){ Vector<String> files= ftpClient.listFileInDir("/"+dir); for (String file :files) System.out.println("/"+dir+"/"+new String(file.getBytes("ISO-8859-1"),"utf-8")); } ftpClient.uploadFile("F:\\xampp\\htdocs\\test\\www.php","/www.php"); } }
package han;

/**
 * Created by han on 2017/8/30.
 */
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
import org.apache.commons.net.ftp.FTPSClient;
import org.apache.log4j.Logger;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Vector;

public class FtpClient{

    private static final Logger logger = Logger.getLogger(FtpClient.class);

    private FTPClient client;

    public FtpClient(boolean ftps) {
        if (ftps) {
            client = new FTPSClient(true);
        } else {
            client = new FTPClient();
        }
    }

    public boolean changeDir(String remotePath) throws Exception {
        return client.changeWorkingDirectory(remotePath);
    }

    public boolean connect(String host, String login, String password, int port) throws Exception {
        logger.debug("FTP request connect to " + host + ":" + port);
        client.connect(host, port);
        int reply = client.getReplyCode();
        if (FTPReply.isPositiveCompletion(reply)) {
            logger.debug("FTP request login as " + login);
            if (client.login(login, password)) {
                client.enterLocalPassiveMode();
                return true;
            }
        }
        disconnect();
        return false;
    }

    public void disconnect() throws Exception {
        logger.debug("FTP request disconnect");
        client.disconnect();
    }


    protected boolean downloadFileAfterCheck(String remotePath, String localFile) throws IOException {

        boolean rst;
        FileOutputStream out = null;
        try {
            File file = new File(localFile);
            if (!file.exists()) {
                out = new FileOutputStream(localFile);
                rst = client.retrieveFile(remotePath, out);
            } else {
                rst = true;
            }
        } finally {
            if (out != null) {
                out.close();
            }
        }
        if (out != null) {
            out.close();
        }
        return rst;
    }

    protected boolean downloadFile(String remotePath, String localFile) throws IOException {

        boolean rst;
        FileOutputStream out = null;
        try {
            out = new FileOutputStream(localFile);
            rst = client.retrieveFile(remotePath, out);
        } finally {
            if (out != null) {
                out.close();
            }
        }
        return rst;
    }

    public Vector<String> listFileInDir(String remoteDir) throws Exception {
        if (changeDir(remoteDir)) {
            FTPFile[] files = client.listFiles();
            Vector<String> v = new Vector<String>();
            for (FTPFile file : files) {
                if (!file.isDirectory()) {
                    v.addElement(file.getName());
                }
            }
            return v;
        } else {
            return null;
        }
    }

    public boolean uploadFile(String localFile, String remotePath) throws IOException {
        FileInputStream in = new FileInputStream(localFile);
        boolean rst;
        try {
            rst = client.storeFile(remotePath, in);
        } finally {
            in.close();
        }
        return rst;
    }


    public Vector<String> listSubDirInDir(String remoteDir) throws Exception {
        if (changeDir(remoteDir)) {
            FTPFile[] files = client.listFiles();
            Vector<String> v = new Vector<String>();
            for (FTPFile file : files) {
                if (file.isDirectory()) {
                    v.addElement(file.getName());
                }
            }
            return v;
        } else {
            return null;
        }
    }

    protected boolean createDirectory(String dirName) {
        try {
            return client.makeDirectory(dirName);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }


    public boolean isARemoteDirectory(String path) {
        String cache = "/";
        try {
            cache = client.printWorkingDirectory();
        } catch (NullPointerException e) {
            //nop
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            boolean isDir = changeDir(path);
            changeDir(cache);
            return isDir;
        } catch (IOException e) {
            //e.printStackTrace();
        } catch (Exception e) {
            //e.printStackTrace();
        }
        return false;
    }

    public String getWorkingDirectory() {
        try {
            return client.printWorkingDirectory();
        } catch (IOException e) {
        }
        return null;
    }

}