Spring Boot集成SFTP快速入门Demo

news2024/9/21 16:33:10

1.什么是SFTP?

SFTP(SSH File Transfer Protocol,也称 Secret File Transfer Protocol),是一种基于SSH(安全外壳)的安全的文件传输协议。使用SFTP协议可以在文件传输过程中提供一种安全的加密算法,从而保证数据的安全传输,所以SFTP是非常安全的。但是,由于这种传输方式使用了加密/解密技术,所以传输效率比普通的FTP要低。 SFTP是SSH的一部分,SFTP没有单独的守护进程,它必须使用SSHD守护进程(端口号默认是22)来完成相应的连接操作,sftp服务作为ssh的一个子服务,是通过 /etc/ssh/sshd_config 配置文件中的 Subsystem 实现的,如果没有配置 Subsystem 参数,则系统是不能进行sftp访问的。所以,要分离ssh和sftp服务的话,基本的思路是创建两个sshd进程,分别监听在不同的端口,一个作为ssh服务的deamon,另一个作为sftp服务的deamon。

Spring Integration核心组件

  • SftpSessionFactory: sftp 客户端与服务端的会话工厂。客户端每次访问服务器时都会创建一个 session 对象,且可以通过 SftpSessionCaching 将 session 对象缓存起来,支持 session 共享,即可以在一个会话上进行多个 channel 的操作。如果 session 被重置,则在最后一次 channel 关闭之后,将断开连接。isSharedSession 为 true 时 session 将共享。
  • SftpSessionCaching: sftp 会话缓存工厂。通过 poolSize 和 sessionWaiteTimeout 来设置缓存池大小和会话等待超时时间。缓存池默认是无限大,超时时间默认是 Integer.MAX_VALUE。
  • SftpRemoteFileTemplate: 基于 SftpSessionFactory 创建的 sftp 文件操作模板类。其父类是 RemoteFileTemplate。支持上传、下载、追加、删除、重命名、列表、是否存在。基于输入输出流实现。
  • SftpInboundChannelAdapter: sftp 入站通道适配器。可同步远程目录到本地,且可监听远程文件的操作,可实现下载。
  • SftpOutboundChannelAdapter: sftp 出站通道适配器。实际是一个 sftp 消息处理器,将在服务器与客户端之间创建一个消息传输通道。此处的消息指的是 Message 的 payload,其支持 File、byte[]、String。其支持 ls、nlst、get、rm、mget、mv、put、mput 操作。
  • Channel Adapter: 通道适配器,实际上是适配消息在客户端和服务器之间的传输。inbound adapter 是接收其它系统的消息,outbound adapter 是发送消息到其它系统。
  • @ServiceActivator: 将注解作用的方法注册为处理消息的站点,inputChannel 表示接收消息的通道。

2.环境搭建

docker run -p 22:22 -d atmoz/sftp foo:pass:::upload

验证环境

说明已经可以连接上去了

3.代码工程

实验目标

实现文件上传和下载

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>springboot-demo</artifactId>
        <groupId>com.et</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>sftp</artifactId>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-autoconfigure</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.integration</groupId>
            <artifactId>spring-integration-sftp</artifactId>
            <!--            <version>5.4.1</version>-->
            <version>5.2.8.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
    </dependencies>
</project>

service

package com.et.sftp.service.impl;

import com.et.sftp.config.SftpConfiguration;
import com.et.sftp.service.SftpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.integration.file.remote.FileInfo;
import org.springframework.integration.sftp.session.SftpRemoteFileTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.*;
import java.util.List;


@Slf4j
@Component
public class SftpServiceImpl implements SftpService {

    @Resource
    private SftpRemoteFileTemplate remoteFileTemplate;

    @Resource
    private SftpConfiguration.SftpGateway gateway;

    /**
     * single file upload
     *
     * @param file File
     */
    @Override
    public void uploadFile(File file) {
        gateway.upload(file);
    }

    /**
     * single file upload by byte[]
     *
     * @param bytes bytes
     */
    @Override
    public void uploadFile(byte[] bytes, String name) {
        try {
            gateway.upload(bytes, name);
        } catch (Exception e) {
            log.error("error:", e);
        }
    }

    /**
     * uopload by path
     *
     * @param bytes
     * @param filename
     * @param path
     */
    @Override
    public void upload(byte[] bytes, String filename, String path) {
        try {
            gateway.upload(bytes, filename, path);
        } catch (Exception e) {
            log.error("error:", e);
        }
    }

    /**
     * list files by path
     *
     * @param path
     * @return List<String>
     */
    @Override
    public String[] listFile(String path) {
        try {
            return remoteFileTemplate.execute(session -> {
                return session.listNames(path);
            });
        } catch (Exception e) {
            log.error("error:", e);
        }
        return null;
    }


    /**
     * list file and directory by path
     *
     * @param path
     * @return List<String>
     */
    @Override
    public List<FileInfo> listALLFile(String path) {
        return gateway.listFile(path);
    }

    /**
     * download
     *
     * @param fileName 
     * @param savePath 
     * @return File
     */
    @Override
    public File downloadFile(String fileName, String savePath) {
        try {
            return remoteFileTemplate.execute(session -> {
                remoteFileTemplate.setAutoCreateDirectory(true);
                boolean existFile = session.exists(fileName);
                if (existFile) {
                    InputStream is = session.readRaw(fileName);
                    return convertInputStreamToFile(is, savePath);
                } else {
                    return null;
                }
            });
        } catch (Exception e) {
            log.error("error:", e);
        }
        return null;
    }

    /**
     * read file
     *
     * @param fileName
     * @return InputStream
     */

    @Override
    public InputStream readFile(String fileName) {
        return remoteFileTemplate.execute(session -> {
            return session.readRaw(fileName);
        });
    }

    /**
     * files is exists
     *
     * @param filePath 
     * @return boolean
     */
    @Override
    public boolean existFile(String filePath) {
        try {
            return remoteFileTemplate.execute(session ->
                    session.exists(filePath));
        } catch (Exception e) {
            log.error("error:", e);
        }
        return false;
    }

    public void renameFile(String file1, String file2) {
        try {
            remoteFileTemplate.execute(session -> {
                session.rename(file1, file2);
                return true;
            });
        } catch (Exception e) {
            log.error("error:", e);
        }
    }

    /**
     * create directory
     *
     * @param dirName
     * @return
     */

    @Override
    public boolean mkdir(String dirName) {
        return remoteFileTemplate.execute(session -> {
            if (!existFile(dirName)) {

                return session.mkdir(dirName);
            } else {
                return false;
            }
        });
    }

    /**
     * delete file
     *
     * @param fileName 
     * @return boolean
     */
    @Override
    public boolean deleteFile(String fileName) {
        return remoteFileTemplate.execute(session -> {
            boolean existFile = session.exists(fileName);
            if (existFile) {
                return session.remove(fileName);
            } else {
                log.info("file : {} not exist", fileName);
                return false;
            }
        });
    }

    /**
     * batch upload (MultipartFile)
     *
     * @param files List<MultipartFile>
     * @throws IOException
     */
    @Override
    public void uploadFiles(List<MultipartFile> files, boolean deleteSource) throws IOException {
        try {
            for (MultipartFile multipartFile : files) {
                if (multipartFile.isEmpty()) {
                    continue;
                }
                File file = convert(multipartFile);
                gateway.upload(file);
                if (deleteSource) {
                    file.delete();
                }
            }
        } catch (Exception e) {
            log.error("error:", e);
        }
    }

    /**
     * batch upload (MultipartFile)
     *
     * @param files List<MultipartFile>
     * @throws IOException
     */
    @Override
    public void uploadFiles(List<MultipartFile> files) throws IOException {
        uploadFiles(files, true);
    }

    /**
     * single file upload (MultipartFile)
     *
     * @param multipartFile MultipartFile
     * @throws IOException
     */
    @Override
    public void uploadFile(MultipartFile multipartFile) throws IOException {
        gateway.upload(convert(multipartFile));
    }

    @Override
    public String listFileNames(String dir) {
        return gateway.nlstFile(dir);
    }

    @Override
    public File getFile(String dir) {
        return null;
    }

    @Override
    public List<File> mgetFile(String dir) {
        return null;
    }

    @Override
    public boolean rmFile(String file) {
        return false;
    }

    @Override
    public boolean mv(String sourceFile, String targetFile) {
        return false;
    }

    @Override
    public File putFile(String dir) {
        return null;
    }

    @Override
    public List<File> mputFile(String dir) {
        return null;
    }

    @Override
    public String nlstFile(String dir) {
        return gateway.nlstFile(dir);
    }

    private static File convertInputStreamToFile(InputStream inputStream, String savePath) {
        OutputStream outputStream = null;
        File file = new File(savePath);
        try {
            outputStream = new FileOutputStream(file);
            int read;
            byte[] bytes = new byte[1024];
            while ((read = inputStream.read(bytes)) != -1) {
                outputStream.write(bytes, 0, read);
            }
            log.info("convert InputStream to file done, savePath is : {}", savePath);
        } catch (IOException e) {
            log.error("error:", e);
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    log.error("error:", e);
                }
            }
        }
        return file;
    }

    private static File convert(MultipartFile file) throws IOException {
        File convertFile = new File(file.getOriginalFilename());
        convertFile.createNewFile();
        FileOutputStream fos = new FileOutputStream(convertFile);
        fos.write(file.getBytes());
        fos.close();
        return convertFile;
    }
}
package com.et.sftp.service;

import org.springframework.integration.file.remote.FileInfo;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;


public interface SftpService {


    void uploadFile(File file);

    void uploadFile(byte[] bytes, String name);

    
    void upload(byte[] bytes, String filename, String path);

    
    String[] listFile(String path);

    List<FileInfo> listALLFile(String path);

    
    File downloadFile(String fileName, String savePath);


    InputStream readFile(String fileName);

    
    boolean existFile(String filePath);


    boolean mkdir(String dirName);

    boolean deleteFile(String fileName);

    
    void uploadFiles(List<MultipartFile> files, boolean deleteSource) throws IOException;

    
    void uploadFiles(List<MultipartFile> files) throws IOException;

    
    void uploadFile(MultipartFile multipartFile) throws IOException;


   
    String listFileNames(String dir);


    File getFile(String dir);

   
    List<File> mgetFile(String dir);

  
    boolean rmFile(String file);

    
    boolean mv(String sourceFile, String targetFile);

   
    File putFile(String dir);

    
    List<File> mputFile(String dir);


    //void upload(File file);

    //void upload(byte[] inputStream, String name);

    //List<File> downloadFiles(String dir);


    String nlstFile(String dir);
}

config

在配置SFTP adapters之前,需要配置SFTP Session Factory;Spring Integration提供了如下xml和spring boot的定义方式。 每次使用 SFTP adapter,都需要Session Factory会话对象,一般情况,都会创建一个新的SFTP会话。同时还提供了Session的缓存功能。Spring integration中的Session Factory是依赖于JSch库来提供。 JSch支持在一个连接配置上多个channel的操作。原生的JSch技术开发,在打开一个channel操作之前,需要建立Session的连接。同样的,默认情况,Spring Integration为每一个channel操作使用单独的物理连接。在3.0版本发布之后,Cache Session Factory 出现 (CachingSessionFactory),将Session Factory包装在缓存中,支持Session共享,可以在一个连接上支持多个JSch Channel的操作。如果缓存被重置,在最后一次channel关闭之后,才会断开连接。

package com.et.sftp.config;

import com.jcraft.jsch.ChannelSftp;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.expression.common.LiteralExpression;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.integration.annotation.Gateway;
import org.springframework.integration.annotation.MessagingGateway;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.core.MessagingTemplate;
import org.springframework.integration.file.FileNameGenerator;
import org.springframework.integration.file.remote.FileInfo;
import org.springframework.integration.file.remote.session.CachingSessionFactory;
import org.springframework.integration.file.remote.session.SessionFactory;
import org.springframework.integration.file.support.FileExistsMode;
import org.springframework.integration.sftp.gateway.SftpOutboundGateway;
import org.springframework.integration.sftp.outbound.SftpMessageHandler;
import org.springframework.integration.sftp.session.DefaultSftpSessionFactory;
import org.springframework.integration.sftp.session.SftpRemoteFileTemplate;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Payload;

import javax.annotation.Resource;
import java.io.File;
import java.util.List;



@Configuration
@EnableConfigurationProperties(SftpProperties.class)
public class SftpConfiguration {

    @Resource
    private SftpProperties properties;


    @Bean
    public MessagingTemplate messagingTemplate(BeanFactory beanFactory) {
        MessagingTemplate messagingTemplate = new MessagingTemplate();
        messagingTemplate.setBeanFactory(beanFactory);
        return messagingTemplate;
    }

    @Bean
    public SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory() {
        DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
        factory.setHost(properties.getHost());
        factory.setPort(properties.getPort());
        factory.setUser(properties.getUsername());
        factory.setPassword(properties.getPassword());
        factory.setAllowUnknownKeys(true);
//        factory.setTestSession(true);
//        return factory;
        return new CachingSessionFactory<ChannelSftp.LsEntry>(factory);
    }

    @Bean
    public SftpRemoteFileTemplate remoteFileTemplate(SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory) {
        return new SftpRemoteFileTemplate(sftpSessionFactory);
    }


    @Bean
    @ServiceActivator(inputChannel = "downloadChannel")
    public MessageHandler downloadHandler(SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory) {
        SftpOutboundGateway sftpOutboundGateway = new SftpOutboundGateway(sftpSessionFactory, "mget", "payload");
        sftpOutboundGateway.setOptions("-R");
        sftpOutboundGateway.setFileExistsMode(FileExistsMode.REPLACE_IF_MODIFIED);
        sftpOutboundGateway.setLocalDirectory(new File(properties.getLocalDir()));
        sftpOutboundGateway.setAutoCreateLocalDirectory(true);
        return sftpOutboundGateway;
    }


    @Bean
    @ServiceActivator(inputChannel = "uploadChannel", outputChannel = "testChannel")
    public MessageHandler uploadHandler(SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory) {
        SftpMessageHandler handler = new SftpMessageHandler(sftpSessionFactory);
        handler.setRemoteDirectoryExpression(new LiteralExpression(properties.getRemoteDir()));
//        handler.setChmod();
        handler.setFileNameGenerator(message -> {
            if (message.getPayload() instanceof File) {
                return ((File) message.getPayload()).getName();
            } else {
                throw new IllegalArgumentException("File expected as payload.");
            }
        });
        return handler;
    }

    @Bean
    @ServiceActivator(inputChannel = "uploadByteChannel")
    public MessageHandler multiTypeHandler(SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory) {
        SftpMessageHandler handler = new SftpMessageHandler(sftpSessionFactory);
        handler.setRemoteDirectoryExpression(new LiteralExpression(properties.getRemoteDir()));
        handler.setFileNameGenerator(message -> {
            if (message.getPayload() instanceof byte[]) {
                return (String) message.getHeaders().get("name");
            } else {
                throw new IllegalArgumentException("byte[] expected as payload.");
            }
        });
        return handler;
    }


    @Bean
    @ServiceActivator(inputChannel = "lsChannel")
    public MessageHandler lsHandler(SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory) {
        SftpOutboundGateway sftpOutboundGateway = new SftpOutboundGateway(sftpSessionFactory, "ls", "payload");
        sftpOutboundGateway.setOptions("-R"); 
        return sftpOutboundGateway;
    }


    @Bean
    @ServiceActivator(inputChannel = "nlstChannel")
    public MessageHandler listFileNamesHandler(SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory) {
        SftpOutboundGateway sftpOutboundGateway = new SftpOutboundGateway(sftpSessionFactory, "nlst", "payload");
        return sftpOutboundGateway;
    }

    @Bean
    @ServiceActivator(inputChannel = "getChannel")
    public MessageHandler getFileHandler(SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory) {
        SftpOutboundGateway sftpOutboundGateway = new SftpOutboundGateway(sftpSessionFactory, "get", "payload");
        sftpOutboundGateway.setOptions("-R");
        sftpOutboundGateway.setFileExistsMode(FileExistsMode.REPLACE_IF_MODIFIED);
        sftpOutboundGateway.setLocalDirectory(new File(properties.getLocalDir()));
        sftpOutboundGateway.setAutoCreateLocalDirectory(true);
        return sftpOutboundGateway;
    }

    /**
     * create by: qiushicai
     * create time: 2020/11/20
     *
     * @return
     */
    @Bean
    @ServiceActivator(inputChannel = "abc")
    public MessageHandler abcHandler(SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory) {
        SftpMessageHandler handler = new SftpMessageHandler(sftpSessionFactory);
        handler.setRemoteDirectoryExpression(new LiteralExpression(properties.getRemoteDir()));
        handler.setFileNameGenerator(message -> {
            if (message.getPayload() instanceof byte[]) {
                System.out.println("receive message:" + new String((byte[]) message.getPayload()));
                message.getHeaders().forEach((k, v) -> System.out.println("\t\t|---" + k + "=" + v));
                return "ok";
            } else {
                throw new IllegalArgumentException("byte[] expected as payload.");
            }
        });
        return handler;
    }

    /**
     *
     *  the #root object is the Message, which has two properties (headers and payload) that allow such expressions as payload, payload.thing, headers['my.header'], and so on
     *
     *  link{ https://stackoverflow.com/questions/46650004/spring-integration-ftp-create-dynamic-directory-with-remote-directory-expressi}
     *  link{ https://docs.spring.io/spring-integration/reference/html/spel.html}
     * @return
     */
    @Bean
    @ServiceActivator(inputChannel = "toPathChannel")
    public MessageHandler pathHandler() {
        SftpMessageHandler handler = new SftpMessageHandler(sftpSessionFactory());
        // automatically create the remote directory
        handler.setAutoCreateDirectory(true);
        handler.setRemoteDirectoryExpression(new SpelExpressionParser().parseExpression("headers[path]"));
        handler.setFileNameGenerator(new FileNameGenerator() {
            @Override
            public String generateFileName(Message<?> message) {
                return (String) message.getHeaders().get("filename");
            }
        });
        return handler;
    }


    /**
     * <ul>
     * <li>ls (list files)
     * <li> nlst (list file names)
     * <li> get (retrieve a file)
     * <li> mget (retrieve multiple files)
     * <li> rm (remove file(s))
     * <li> mv (move and rename file)
     * <li> put (send a file)
     * <li> mput (send multiple files)
     * </ul>
     *
     * @author :qiushicai
     * @date :Created in 2020/11/20
     * @description: outbound gateway API
     * @version:
     */
    @MessagingGateway
    public interface SftpGateway {

        //ls (list files)
        @Gateway(requestChannel = "lsChannel")
        List<FileInfo> listFile(String dir);


        @Gateway(requestChannel = "nlstChannel")
        String nlstFile(String dir);



        @Gateway(requestChannel = "getChannel")
        File getFile(String dir);

        @Gateway(requestChannel = "mgetChannel")
        List<File> mgetFile(String dir);

        @Gateway(replyChannel = "rmChannel")
        boolean rmFile(String file);

        @Gateway(replyChannel = "mvChannel")
        boolean mv(String sourceFile, String targetFile);

        @Gateway(requestChannel = "putChannel")
        File putFile(String dir);

        @Gateway(requestChannel = "mputChannel")
        List<File> mputFile(String dir);

        @Gateway(requestChannel = "uploadChannel")
        void upload(File file);

        @Gateway(requestChannel = "uploadByteChannel")
        void upload(byte[] inputStream, String name);

        @Gateway(requestChannel = "toPathChannel")
        void upload(@Payload byte[] file, @Header("filename") String filename, @Header("path") String path);

        @Gateway(requestChannel = "downloadChannel")
        List<File> downloadFiles(String dir);

    }
}

从Spring Integration 3.0开始,通过SftpSession对象提供了一个新类Remote File Template。提供了Sftp文件发送、检索、删除和重命名文件的方法。此外,还提供了一个执行方法,允许调用者在会话上执行多个操作。在所有情况下,模板负责可靠地关闭会话。 SftpRemoteFileTemplate继承Remote File Template,可以很容易的实现对SFTP文件的发送(包括文件追加,替换等),检索,删除和重命名。

package com.et.sftp.config;


import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

@Data
@ConfigurationProperties(prefix = "sftp")
public class SftpProperties {
    private String host;
    private Integer port;
    private String password;
    private String username;
    private String remoteDir;
    private String localDir;
}

application.properties

##sftp properties
sftp.host=127.0.0.1
sftp.port=22
sftp.username=foo
sftp.password=pass
sftp.remoteDir=/upload
sftp.localDir=D:\\tmp\\sync-files

以上只是一些关键代码,所有代码请参见下面代码仓库

代码仓库

  • https://github.com/Harries/springboot-demo

4.测试

在测试包里面有专门的测试类,具体可以查看源代码

文件是否存在

@Test
void testExistFile() {
    boolean existFile = sftpService.existFile("/upload/home222.js");
    System.out.println(existFile);
}

列出目录下的文件

@Test
void listFileTest() {
    sftpService.listALLFile("/upload").stream().forEach(System.out::println);
}

下载文件

 @Test
    void testDownLoad() throws Exception {
        sftpService.downloadFile("/upload/home.js", "D:\\tmp\\c222c.js");
//
//        sftpService.uploadFile(new File("D:\\tmp\\cc.js"));


//        InputStream inputStream = sftpService.readFile("/upload/cc.js");
//
//        IOUtils.copy(inputStream, new FileOutputStream(new File("D:\\tmp\\" + UUID.randomUUID() + ".js")));

    }

上传文件

@Test
void uploadFile() {
    sftpService.uploadFile(new File("D:\\tmp\\cc.js"));
}

5.引用

  • SFTP Adapters
  • Spring Boot集成SFTP快速入门Demo | Harries Blog™

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1936788.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

ABAP打印WORD的解决方案

客户要求按照固定格式输出到WORD模板中&#xff0c;目前OLE和DOI研究了均不太适合用于这种需求。 cl_docx_document类可以将WORD转化为XML文件&#xff0c;利用替换字符串方法将文档内容进行填充同 时不破坏WORD现有格式。 首先需要将WORD的单元格用各种预定义的字符进行填充…

Redis的AOF持久化策略(AOF的工作流程、AOF的重写流程,操作演示、注意事项等)

文章目录 缓冲AOF 策略(append only file)AOF 的工作流程AOF 缓冲区策略AOF 的重写机制重写完的AOF文件为什么可以变小&#xff1f;AOF 重写流程 缓冲AOF 策略(append only file) AOF 的核心思路是 “实时备份“&#xff0c;只要我添加了新的数据或者更新了新的数据&#xff0…

价格较低,功能最强?OpenAI 推出 GPT-4o mini,一个更小、更便宜的人工智能模型

OpenAI美东时间周四推出“GPT-4o mini”&#xff0c;入局“小而精”AI模型竞争&#xff0c;称这款新模型是“功能最强、成本偏低的模型”&#xff0c;计划今后整合图像、视频、音频到这个模型中。 OpenAI表示&#xff0c;GPT-4o mini 相较于 OpenAI 目前最先进的 AI 模型更加便…

FairGuard游戏加固入选《嘶吼2024网络安全产业图谱》

2024年7月16日&#xff0c;国内网络安全专业媒体——嘶吼安全产业研究院正式发布《嘶吼2024网络安全产业图谱》(以下简称“产业图谱”)。 本次发布的产业图谱&#xff0c;共涉及七大类别&#xff0c;127个细分领域。全面展现了网络安全产业的构成和重要组成部分&#xff0c;探…

微软发布iOS/安卓正式版Designer应用,AI修图功能助力创意设计

一、Microsoft Designer应用正式上线 AITOP100平台获悉&#xff0c;微软一直致力于为用户提供优质的创意工具&#xff0c;此次推出的Microsoft Designer应用正是其在移动端的重要布局。这款应用已正式上线iOS、Android、Windows和网页版本&#xff0c;满足不同用户的需求。微软…

Stable Diffusion 使用详解(2)---- 图生图原理,操作,参数

目录 背景 图生图原理 基本原理 1. 扩散模型基础 2. 图生图的具体流程 3. 关键技术点 4. 应用实例 CLIP 原理 1.基本概念 2. 核心特点 使用及参数 随机种子 重绘幅度 图像宽高 采样方法 1. DPM&#xff08;扩散概率模型&#xff09; 2. SDE&#xff08;随机微…

大语言模型-检索测评指标

1. MRR &#xff08;Mean Reciprocal Rank&#xff09;平均倒数排名&#xff1a; 衡量检索结果排序质量的指标。 计算方式&#xff1a; 对于每个查询&#xff0c;计算被正确检索的文档的最高排名的倒数的平均值&#xff0c;再对所有查询的平均值取均值。 意义&#xff1a; 衡量…

ChatTTS超强的真人AI语音助手下载使用教程

简介 ChatTTS是专门为对话场景设计的文本转语音模型&#xff0c;支持多人同时对话&#xff0c;适用的场景非常丰富&#xff0c;比如LLM助手对话任务&#xff0c;视频配音、声音克隆等。同时支持英文和中文两种语言。最大的模型使用了10万小时以上的中英文数据进行训练&#xf…

【Android】 dp与sp,加冕为王

目录 重要概念 屏幕尺寸 屏幕分辨率 屏幕像素密度 基础知识&#xff1a; ppi pt DPI 的定义和重要性 Android 中的 DPI 级别 px dp&#xff08;Density Independent Pixels&#xff09; sp&#xff08;Scale-independent Pixels&#xff09; 安卓的dp/dip、sp 虚拟…

设置浏览器网页全屏

在日常笔记本上办公时&#xff0c;由于屏幕较小&#xff0c;为了尽可能多和方便的显示浏览器网页上的内容&#xff0c;可以设置网页全屏的方式&#xff0c;去掉屏幕顶端的网址栏和底端栏&#xff0c;具体设置如下&#xff1a; 以Edge浏览器和Google Chrome浏览器为例&#xff…

如何免费用java c#实现手机在网状态查询

今天分享手机在网状态查询接口&#xff0c;该接口适用的场景非常广泛&#xff01;首先我们先讲下什么是手机在网状态&#xff1f;简单来说&#xff0c;就是你得手机号是否还在正常使用中&#xff0c;是否能够及时接收和回复信息&#xff0c;是否能够随时接听和拨打电话。如果你…

通过libx246 libfaac转换推送RTMP音视频直播流

一、RTMP简介及rtmplib库&#xff1a; RTMP协议是Real Time Message Protocol(实时信息传输协议)的缩写&#xff0c;它是由Adobe公司提出的一种应用层的协议&#xff0c;用来解决多媒体数据传输流的多路复用&#xff08;Multiplexing&#xff09;和分包&#xff08;packetizing…

C++ :友元类

友元类的概念和使用 (1)将类A声明为B中的friend class后&#xff0c;则A中所有成员函数都成为类B的友元函数了 (2)代码实战&#xff1a;友元类的定义和使用友元类是单向的 (3)友元类是单向的&#xff0c;代码实战验证 互为友元类 (1)2个类可以互为友元类&#xff0c;代码实战…

相同IP地址仿真测试

相同IP地址仿真测试 背景与挑战解决方案技术优势功能特点 背景与挑战 在汽车电子领域&#xff0c;电子控制单元&#xff08;ECU&#xff09;的测试是确保其功能性和可靠性的关键步骤。然而&#xff0c;当测试场景涉及多个配置相同IP地址的ECU时&#xff0c;传统的测试方法面临…

GooglePlay 金融品类政策更新(7月17号)

距离上次政策大更新&#xff08;4月5号&#xff09;才过去了3个月&#xff0c;Google Play又迎来了一次大更新&#xff0c;不得不说Google Play的要求越来越高了。 我们来梳理一下这次GooglePlay针对金融品类更新了哪些政策: 1.要求提供金融产品和服务的开发者必须注册为组织…

IDEA的常见代码模板的使用

《IDEA破解、配置、使用技巧与实战教程》系列文章目录 第一章 IDEA破解与HelloWorld的实战编写 第二章 IDEA的详细设置 第三章 IDEA的工程与模块管理 第四章 IDEA的常见代码模板的使用 第五章 IDEA中常用的快捷键 第六章 IDEA的断点调试&#xff08;Debug&#xff09; 第七章 …

STM32使用SPI向W25Q64存储信息(HAL库)

SPI全双工通信&#xff1a;全双工在时钟脉冲周期的每一个周期内&#xff0c;每当主设备同时发送一个字节的同时&#xff0c;会接受从设备接受一个字节数据&#xff0c;SPI全双工最大的特点就是发送和接受数据同步进行&#xff0c;发送多少数据就要接受多少数据。使用全双工通信…

vst 算法R语言手工实现 | Seurat4 筛选高变基因的算法

1. vst算法描述 &#xff08;1&#xff09;为什么需要矫正 image source: https://ouyanglab.com/singlecell/basic.html In this panel, we observe that there is a very strong positive relationship between a gene’s average expression and its observed variance. I…

【iOS】static、extern、const、auto关键字以及联合使用

目录 前言extern关键字static关键字const关键字 联合使用static和externstatic和constextern和const auto关键字 先了解一下静态变量所在的全局/静态区的特点&#xff1a;【iOS】内存五大分区 前言 上面提到的全局/静态区中存放的是全局变量或静态变量&#xff1a; 全局变量…

逻辑回归(Logistic Regression,LR)

分类和回归是机器学习的两个主要问题。 分类处理的是离散数据回归处理的是连续数据 线性回归&#xff1a;回归 拟合一条线预测函数&#xff1a; 逻辑回归&#xff1a;分类——找到一条线可以将不同类别区分开 虽然称为逻辑回归&#xff0c;但是实际是一种分…