• java ftp上传文件


    //这边path指的是相对路径,需要切换到,path目录,然后
    public static void upload(String server, int port, String user, String pwd, List<String> sourcePaths, List<String> desPaths, String filename) {
    if (sourcePaths.size() == 0 || desPaths.size() == 0) {
    return;
    }
    if (sourcePaths.size() != desPaths.size()) {
    System.out.println("源文件地址与目标地址不匹配!");
    }
    FTPClient client = new FTPClient();
    FileInputStream inputStream = null;
    try {
    client.connect(server, port);
    client.login(user, pwd);
    for (int i = 0; i < sourcePaths.size(); i++) {
    inputStream = new FileInputStream(sourcePaths.get(i));
    client.changeWorkingDirectory(desPaths.get(i));
    boolean b = client.storeFile(filename, inputStream);
    if (b == false) {
    System.out.println("上传文件:" + sourcePaths.get(i) + "失败!目标主机:" + server);
    }
    }
    client.logout();
    } catch (IOException e) {
    e.printStackTrace();
    } finally {
    try {
    if (inputStream != null) {
    inputStream.close();
    }
    client.disconnect();
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    }
            <dependency>
                <groupId>commons-net</groupId>
                <artifactId>commons-net</artifactId>
                <version>3.3</version>
            </dependency>
  • 相关阅读:
    「LOJ #6500」「雅礼集训 2018 Day2」操作
    「CEOI2013」Board
    CF407B Long Path
    poj 2503 Babelfish 用trie树做
    poj 3414 Pots搜索BFS
    POJ2001 Shortest Prefixes 用trie树实现
    poj3630Phone List用trie树实现
    poj1797Heavy Transportation最大生成树
    hoj题双重筛法
    poj1338 Ugly Numbers
  • 原文地址:https://www.cnblogs.com/chenmz1995/p/10468584.html
Copyright © 2020-2023  润新知