zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    近期目标
    HDU
    BZOJ
    UVALive
    UVA
    HNOI2004 宠物收养所 (平衡二叉树)
    UVA
    HDU
    POJ
    康托展开与逆康托展开模板(O(n^2)/O(nlogn))
  • 原文地址:https://www.cnblogs.com/chenmz1995/p/10468584.html
Copyright © 2011-2022 走看看