所需依赖
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.49</version>
</dependency>
配置文件
server.port=11111
ftp.server.host=192.11.*.*
ftp.server.port=22
ftp.server.username=username
ftp.server.password=password
核心代码
package com.wanyu.util;
import com.jcraft.jsch.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.util.UUID;
@Component
public class SFtpUtil {
private transient Logger log = LoggerFactory.getLogger(SFtpUtil.class);
private ChannelSftp sftp;
private Session session;
@Value("${ftp.server.username}")
private String username;
@Value("${ftp.server.password}")
private String password;
@Val