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>
  • 相关阅读:
    1、如何使用Azure Rest API创建虚拟机
    Ansible---2的Roles使用
    linux下的shell脚本
    生成器 yield和协程
    xshell
    markdown的使用
    加密
    Hbuilder打包app
    尾递归
    jupyter
  • 原文地址:https://www.cnblogs.com/chenmz1995/p/10468584.html
Copyright © 2011-2022 走看看