Coder Social home page Coder Social logo

springboot-ftp's Introduction

SpringBoot-FTP

介绍

使用pool2封装的FtpTemplate.yml配置好FtpClientProperties.java、FtpPoolProperties.java即可开箱即用!

软件架构

基于SpringBoot、commons-net、commons-pool2

安装及使用说明看Ftp配置文件

Ftp yml示例

ftp:
  client:
    host: 127.0.0.1
    login-name: root
    password: 123456
    port: 22

Ftp使用示例

package com.lc.ftp;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import javax.annotation.Resource;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

@SpringBootApplication
public class FtpApplication {
    public static void main(String[] args) {
        SpringApplication.run(FtpApplication.class, args);
    }

    @Resource
    private FtpTemplate ftpTemplate;

    /**
     * 上传图片
     *
     * @return
     */
//    @GetMapping("upload")
    public Boolean upload() {
        InputStream inputStream = null;
        try {
            inputStream = new FileInputStream("C:\\Users\\win10\\Pictures\\test.jpg");
            return ftpTemplate.upload(inputStream, "/t", "tests.jpg");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 删除图片
     *
     * @return
     */
//    @GetMapping("delete")
    public Boolean delete() {
        try {
            return ftpTemplate.delete("/t", "tests.jpg");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
}

springboot-ftp's People

Contributors

skysame avatar my-liu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.