Java处理SSH

2023-11-17

JSch 登录

密码方式:session.setPassword(password);

公私秘钥方式:jsch.addIdentity("~/.ssh/id_rsaxxx");

SFTP简介

SFTP是Secure File Transfer Protocol的缩写,安全文件传送协议。可以为传输文件提供一种安全的加密方法。SFTP 为 SSH的一部份,是一种传输文件到服务器的安全方式。SFTP是使用加密传输认证信息和传输的数据,所以,使用SFTP是非常安全的。但是,由于这种传输方式使用了加密/解密技术,所以传输效率比普通的FTP要低得多,如果您对网络安全性要求更高时,可以使用SFTP代替FTP。

ChannelSftpAPI

ChannelSftp类是JSch实现SFTP核心类,它包含了所有SFTP的方法.

githubAPI地址 : ChannelSftp (JSch API)

sftp代码

pom依赖

<!-- sftp的依赖-->
<dependency>
  <groupId>com.jcraft</groupId>
  <artifactId>jsch</artifactId>
  <version>0.1.55</version>
</dependency>
<dependency>
  <groupId>org.apache.commons</groupId>
  <artifactId>commons-io</artifactId>
  <version>1.3.2</version>
</dependency>
<!-- log日志依赖 -->
<dependency>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-slf4j-impl</artifactId>
  <version>2.11.2</version>
</dependency>

jar包百度自行下载

Java代码

SftpUtil

import com.jcraft.jsch.*;
import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.*;
import java.util.Vector;

/**
 * FTP服务器工具类:
 *      JSch类 通过 SFTP 协议上传文件到 freeSSHd 服务器
 * 
 */
public class SftpUtil {

    private Logger logger = LogManager.getLogger(SftpUtil.class);

    private ChannelSftp sftp;

    private Session session;

    /**
     * 用户名
     */
    private String username;

    /**
     * 密码
     */
    private String password;

    /**
     * 秘钥
     */
    private String privateKey;

    /**
     * FTP服务器Ip
     */
    private String host;

    /**
     * FTP服务器端口号
     */
    private int port;

    /**
     * 构造器:基于密码认证sftp对象
     * @param username  用户名
     * @param password  密码
     * @param host      服务器ip
     * @param port      服务器端口号
     */
    public SftpUtil(String username, String password, String host, int port){
        this.username = username;
        this.password = password;
        this.host = host;
        this.port = port;
    }

    /**
     * 构造器:基于秘钥认证sftp对象
     * @param username   用户名
     * @param privateKey 秘钥
     * @param host       服务器ip
     * @param port       服务器端口号
     */
    public SftpUtil(String username, String privateKey, int port, String host){
        this.username = username;
        this.privateKey = privateKey;
        this.host = host;
        this.port = port;
    }

    /**
     * 连接SFTP服务器
     */
    public void login(){
        JSch jsch = new JSch();
        try{
            if(privateKey != null){
                //设置登陆主机的秘钥
                jsch.addIdentity(privateKey);
            }
            //采用指定的端口连接服务器
            session = jsch.getSession(username,host,port);
            if(password != null){
                //设置登陆主机的密码
                session.setPassword(password);
            }
            //优先使用 password 验证   注:session.connect()性能低,使用password验证可跳过gssapi认证,提升连接服务器速度
            session.setConfig("PreferredAuthentications","password");
            //设置第一次登陆的时候提示,可选值:(ask | yes | no)
            session.setConfig("StrictHostKeyChecking","no");
            session.connect();
            //创建sftp通信通道
            Channel channel = session.openChannel("sftp");
            channel.connect();
            sftp = (ChannelSftp) channel;
            logger.info("sftp server connect success !!");
        }catch (JSchException e){
            logger.error("SFTP服务器连接异常!!", e);
        }
    }

    /**
     * 关闭SFTP连接
     */
    public void logout(){
        if(sftp != null){
            if(sftp.isConnected()){
                sftp.disconnect();
                logger.info("sftp is close already");
            }
        }
        if(session != null){
            if(session.isConnected()){
                session.disconnect();
                logger.info("session is close already");
            }
        }
    }

    /**
     * 将输入流上传到SFTP服务器,作为文件
     *
     * @param directory     上传到SFTP服务器的路径
     * @param sftpFileName  上传到SFTP服务器后的文件名
     * @param input         输入流
     * @throws SftpException
     */
    public void upload(String directory, String sftpFileName, InputStream input) throws SftpException{
        long start = System.currentTimeMillis();
        try{
            //如果文件夹不存在,则创建文件夹
            if(sftp.ls(directory) == null){
                sftp.mkdir(directory);
            }
            //切换到指定文件夹
            sftp.cd(directory);
        }catch (SftpException e){
            //创建不存在的文件夹,并切换到文件夹
            sftp.mkdir(directory);
            sftp.cd(directory);
        }
        sftp.put(input, sftpFileName);
        logger.info("文件上传成功!! 耗时:{}ms",(System.currentTimeMillis() - start));
    }

    /**
     * 上传单个文件
     *
     * @param directory     上传到SFTP服务器的路径
     * @param uploadFileUrl 文件路径
     */
    public void upload(String directory, String uploadFileUrl){
        File file = new File(uploadFileUrl);
        try{
            upload(directory, file.getName(), new FileInputStream(file));
        }catch (FileNotFoundException | SftpException e){
            logger.error("上传文件异常!", e);
        }
    }

    /**
     * 将byte[] 上传到SFTP服务器,作为文件
     *           注: 从String转换成byte[] 需要指定字符集
     *
     * @param directory     上传到SFTP服务器的路径
     * @param sftpFileName  上传SFTP服务器后的文件名
     * @param bytes         字节数组
     */
    public void upload(String directory, String sftpFileName, byte[] bytes){
        try{
            upload(directory, sftpFileName, new ByteArrayInputStream(bytes));
        }catch (SftpException e){
            logger.error("上传文件异常!", e);
        }
    }

    /**
     * 将字符串按照指定编码格式上传到SFTP服务器
     *
     * @param directory       上传到SFTP服务器的路径
     * @param sftpFileName    上传SFTP服务器后的文件名
     * @param dataStr         字符串
     * @param charsetName     字符串的编码格式
     */
    public void upload(String directory, String sftpFileName, String dataStr, String charsetName){
        try{
            upload(directory, sftpFileName, new ByteArrayInputStream(dataStr.getBytes(charsetName)));
        }catch (UnsupportedEncodingException | SftpException e){
            logger.error("上传文件异常!", e);
        }
    }

    /**
     * 下载文件
     *
     * @param directory     SFTP服务器的文件路径
     * @param downloadFile  SFTP服务器上的文件名
     * @param saveFile      保存到本地路径
     */
    public void download(String directory, String downloadFile, String saveFile){
        try{
            if(directory != null && !"".equals(directory)){
                sftp.cd(directory);
            }
            File file = new File(saveFile);
            sftp.get(downloadFile, new FileOutputStream(file));
        }catch (SftpException | FileNotFoundException e){
            logger.error("文件下载异常!", e);
        }
    }

    /**
     * 下载文件
     *
     * @param directory     SFTP服务器的文件路径
     * @param downloadFile  SFTP服务器上的文件名
     * @return              字节数组
     */
    public byte[] download(String directory, String downloadFile){
        try{
            if(directory != null && !"".equals(directory)){
                sftp.cd(directory);
            }
            InputStream inputStream = sftp.get(downloadFile);
            return IOUtils.toByteArray(inputStream);
        }catch (SftpException | IOException e){
            logger.error("文件下载异常!", e);
        }
        return null;
    }

    /**
     * 下载文件
     *
     * @param directory     SFTP服务器的文件路径
     * @param downloadFile  SFTP服务器上的文件名
     * @return              输入流
     */
    public InputStream downloadStream(String directory, String downloadFile){
        try{
            if(directory != null && !"".equals(directory)){
                sftp.cd(directory);
            }
            return sftp.get(downloadFile);
        }catch (SftpException e){
            logger.error("文件下载异常!", e);
        }
        return null;
    }

    /**
     * 删除文件
     *
     * @param directory         SFTP服务器的文件路径
     * @param deleteFileName    删除的文件名称
     */
    public void delete(String directory, String deleteFileName){
        try{
            sftp.cd(directory);
            sftp.rm(deleteFileName);
        }catch (SftpException e){
            logger.error("文件删除异常!", e);
        }
    }

    /**
     * 删除文件夹
     *
     * @param directory         SFTP服务器的文件路径
     */
    public void delete(String directory){
        Vector vector = listFiles(directory);
        vector.remove(0);
        vector.remove(0);
        for(Object v : vector){
            ChannelSftp.LsEntry lsEntry = (ChannelSftp.LsEntry)v;
            try{
                sftp.cd(directory);
                sftp.rm(lsEntry.getFilename());
            }catch (SftpException e){
                logger.error("文件删除异常!", e);
            }
        }
    }

    /**
     * 获取文件夹下的文件
     *
     * @param directory     路径
     * @return
     */
    public Vector<?> listFiles(String directory){
        try{
            if(isDirExist(directory)){
                Vector<?> vector =  sftp.ls(directory);
                //移除上级目录和根目录:"." ".."
                vector.remove(0);
                vector.remove(0);
                return vector;
            }
        }catch (SftpException e){
            logger.error("获取文件夹信息异常!", e);
        }
        return null;
    }

    /**
     * 检测文件夹是否存在
     *
     * @param directory     路径
     * @return
     */
    public boolean booleanUrl(String directory){
        try{
            if(sftp.ls(directory) == null){
                return false;
            }
        }catch (Exception e){
            logger.error("检测文件夹异常!", e);
        }
        return true;
    }

    /**
     * 创建一个文件目录
     *
     * @param createpath        路径
     * @return
     */
    public boolean createDir(String createpath) {
        try {
            if (isDirExist(createpath)) {
                this.sftp.cd(createpath);
                return true;
            }
            String pathArry[] = createpath.split("/");
            StringBuffer filePath = new StringBuffer("/");
            for (String path : pathArry) {
                if (path.equals("")) {
                    continue;
                }
                filePath.append(path + "/");
                if (isDirExist(filePath.toString())) {
                    sftp.cd(filePath.toString());
                } else {
                    // 建立目录
                    sftp.mkdir(filePath.toString());
                    // 进入并设置为当前目录
                    sftp.cd(filePath.toString());
                }
            }
            this.sftp.cd(createpath);
        } catch (SftpException e) {
            logger.error("目录创建异常!", e);
            return false;
        }
        return true;
    }

    /**
     * 判断目录是否存在
     * @param directory     路径
     * @return
     */
    public boolean isDirExist(String directory) {
        boolean isDirExistFlag = false;
        try {
            SftpATTRS sftpATTRS = this.sftp.lstat(directory);
            isDirExistFlag = true;
            return sftpATTRS.isDir();
        } catch (Exception e) {
            if (e.getMessage().toLowerCase().equals("no such file")) {
                isDirExistFlag = false;
            }
        }
        return isDirExistFlag;
    }
    
    /**
	 * 方法功能说明:目录不存在时创建目录  
	 * @参数: @param path      
	 * @return void     
	 * @throws
	 */
    public void mkdirs(String path){
		File file = new File(path);
		String fs = file.getParent();
		file = new File(fs);
		if(!file.exists()){
			file.mkdirs();
		}
	}
    /**
    * 判断文件或目录是否存在
    * @param directory     路径
    * @return
    */
    public boolean isExist(String path,ChannelSftp sftp){
        boolean  isExist=false;
        try {
            sftp.lstat(path);
            isExist = true;
        } catch (Exception e) {
            if (e.getMessage().toLowerCase().equals("no such file")) {
                isExist = false;
            }
        }
        return isExist;
    }
}

JschUtil

package com.jmanager.common.utils;

import com.jcraft.jsch.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * @Description:
 * @Author zhou
 * @Date 2021/4/3 - 14:50
 */
public class JschUtilRe {
    Logger logger = LoggerFactory.getLogger(JschUtilRe.class);

    public static final int PORT4SSH = 22;

    private Session session;

    private JschUtilRe(String user, String host, String password) {

        session = getSession(user, host, password);
    }
    /**
     * 定义端口,获取session会话
     * @param user
     * @param host
     * @param password
     * @param port
     */
    private JschUtilRe(String user, String host, String password, int port) {

        session = getSession(user, host, password, port);
    }
    /**
     * 获得实例
     * @param user
     * @param host
     * @param password
     * @return
     */
    public static JschUtilRe getInstance(String user, String host, String password) {
        return new JschUtilRe(user, host, password);
    }
    public static JschUtilRe getInstance(String user, String host, String password, int port) {
        return new JschUtilRe(user, host, password,port);
    }
    public static String getTestHost(String user, String host, String password) {
        JSch jsch = new JSch();
        Session session = null;
        try {
            if("免密".equals(password)) {
                jsch.addIdentity("~/.ssh/id_rsa");
                session = jsch.getSession(user, host, PORT4SSH);
            } else {
                session = jsch.getSession(user, host, PORT4SSH);
                session.setPassword(password);
            }
            session.setConfig("StrictHostKeyChecking", "no");
            session.connect();
        } catch (JSchException e) {
            return e.getMessage();
        } finally {
            if (session != null) {
                session.disconnect();
            }
        }
        return "yes";
    }

    public Session getSession() {
        return session;
    }
    // 获得回话session,定义端口port,ssh默认端口是22,亦可传入其他值
    private Session getSession(String user, String host, String password,int port) {
        JSch jsch = new JSch();
        Session session = null;
        logger.info(user + host +password + port);
        try {
            if("免密".equals(password)) {
                jsch.addIdentity("~/.ssh/id_rsa");
                session = jsch.getSession(user, host, port);
            } else {
                session = jsch.getSession(user, host, port);
                session.setPassword(password);
            }
            session.setConfig("StrictHostKeyChecking", "no");
            session.connect();
        } catch (JSchException e) {
            logger.error(e.toString());
        }
        return session;
    }
    // 获得回话session
    private Session getSession(String user, String host, String password) {
        JSch jsch = new JSch();
        Session session = null;
        try {
            if("免密".equals(password)) {
                jsch.addIdentity("~/.ssh/id_rsa");
                session = jsch.getSession(user, host, PORT4SSH);
            } else {
                session = jsch.getSession(user, host, PORT4SSH);
                session.setPassword(password);
            }
            session.setConfig("StrictHostKeyChecking", "no");
            session.connect();
        } catch (JSchException e) {
            logger.error(e.toString());
        }
        return session;
    }

    // 执行command
    public String execCommand(String cmd) {
        StringBuffer result = new StringBuffer("");
        BufferedReader reader = null;
        Channel channel = null;
        Session session = this.getSession();
        try {
            channel = session.openChannel("exec");
            ((ChannelExec) channel).setCommand(cmd);
            channel.setInputStream(null);
            channel.connect();
            InputStream in = channel.getInputStream();
            reader = new BufferedReader(new InputStreamReader(in, Charset.forName("utf-8")));
            String buf = null;
            while ((buf = reader.readLine()) != null) {
                result.append(buf + "\n");
            }
        } catch (Exception e) {
            logger.error(e.toString());
        } finally {
            try {
                if (reader != null) {
                    reader.close();
                }
            } catch (IOException e) {
                logger.error(e.toString());
            }
            if (channel != null) {
                channel.disconnect();
            }
        }
        return result.toString();
    }

    public String execCommand(String cmd, String code) {
        StringBuffer result = new StringBuffer("");
        BufferedReader reader = null;
        Channel channel = null;
        Session session = this.getSession();
        try {
            channel = session.openChannel("exec");
            ((ChannelExec) channel).setCommand(cmd);
            channel.setInputStream(null);
            channel.connect();
            InputStream in = channel.getInputStream();
            reader = new BufferedReader(new InputStreamReader(in, Charset.forName(code)));
            String buf = null;
            while ((buf = reader.readLine()) != null) {
                result.append(buf + "\n");
            }
        } catch (Exception e) {
            logger.error(e.toString());
        } finally {
            try {
                if (reader != null) {
                    reader.close();
                }
            } catch (IOException e) {
                logger.error(e.toString());
            }
            if (channel != null) {
                channel.disconnect();
            }
        }
        return result.toString();
    }

    // 检查目录是否存在,不存在自动创建
    public void checkDir(String dir) {
        StringBuffer buf = new StringBuffer("[[ -d ");
        buf.append(dir);
        buf.append(" ]] || mkdir -p " + dir);
        String result = execCommand(buf.toString());
    }
    public boolean checkFileExist(String fileName) {
        String result = execCommand("ls " + fileName);
        return result.contains(fileName);
    }
    // 读取文件中内容
    public String headFileContent(String pathAndFileName) {
        String content = null;
        String cmd = ". ~/.bash_profile;head -n 10 " + pathAndFileName;
        content = execCommand(cmd);
        return content;
    }
    // 获得某路径下的文件
    public ArrayList<String> getDirFileList(String path) {
        ArrayList<String> fileList = new ArrayList<String>();
        boolean checked = checkPathExist(path);
        if (checked) {

            String cmd = "cd " + path + ";ls -l";
            String result = execCommand(cmd);
            String[] results = result.split("\n");
            for (String res : results) {
                if (res.startsWith("-")) {
                    String[] ress = res.split(" ");
                    fileList.add(ress[ress.length - 1]);
                }
            }
        }
        return fileList;
    }
    // 读取文件中内容
    public String readFileContent(String pathAndFileName) {
        String content = null;
        String cmd = ". ~/.bash_profile;cat " + pathAndFileName;
        content = execCommand(cmd);
        return content;
    }
    // 逐行读取文件中内容
    public List<String> readFileContentByLine(String pathAndFileName) {
        List<String> res = new ArrayList<>();
        if (checkFileExist(pathAndFileName)) {
            Channel channel = null;
            try {
                channel = session.openChannel("sftp");
                channel.connect();
                ChannelSftp sftp = (ChannelSftp) channel;
                InputStream stream = sftp.get(pathAndFileName);
                BufferedReader br = new BufferedReader(new InputStreamReader(stream));
                String line;
                while ((line = br.readLine()) != null) {
                    res.add(line);
                }
            } catch (JSchException | SftpException | IOException e) {
                e.printStackTrace();
            } finally {
                if (channel != null) {
                    channel.disconnect();
                }
            }
        }
        return res;
    }
    // 读取文件中内容
    public String readFileContent(String path, String fileName) {
        String content = null;
        String cmd = "cat " + path + "/" + fileName;
        content = execCommand(cmd);
        return content;
    }

    // 写入文件
    public void writeFileContent(String path, String fileName, String content) {

        byte[] temp;
        String newStr = "";
        try {
            temp = content.getBytes("utf-8");
            newStr = new String(temp, "gbk");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        String cmd = "cat >" + path + "/" + fileName + " << EOF\n" + newStr + "\nEOF";
        content = execCommand(cmd);
    }
    // 写入文件
    public void writeFileContent(String pathAndFileName, String content) {
        String cmd = ". ~/.bash_profile;cat >" + pathAndFileName + " << 'EOF' \n" + content + "\nEOF";
        execCommand(cmd);
    }
    // 文件备份备份到该路径的backup文件下
    public void backupFile(String path, String fileName) {

        checkDir(path + "/backup");
        StringBuffer cmd = new StringBuffer("scp -r ");
        cmd.append(path).append("/").append(fileName).append(" ").append(path).append("/backup/").append(getTimeStr())
                .append(fileName);
        execCommand(cmd.toString());

    }

    private String getTimeStr() {

        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmm");
        String str = sdf.format(new Date());
        return str;
    }

    // 指定路径新建文件
    public void createFile(String path, String fileName) {
        checkDir(path);
        String cmd = "touch " + path + "/" + fileName;
        execCommand(cmd);
    }

    // 检测路径存在与否
    public boolean checkPathExist(String path) {
        String[] paths = null;
        String p;
        if (path.indexOf("/") != 0) {
            paths = path.split("/");
            p = "";
        } else {
            paths = path.substring(1, path.length()).split("/");
            p = "/";
        }
        for (int i = 0; i < paths.length; i++) {
            String result = execCommand("cd " + p + ";ls");
            List<String> resultList = Arrays.asList(result.split("\n"));
            if (!resultList.contains(paths[i])) {
                return false;
            }
            p += paths[i] + "/";
        }
        return true;
    }

    // 文件copy
    public void copyFile(String pathFrom, String pathTo) {
        StringBuffer buf = new StringBuffer("scp -r ");
        buf.append(pathFrom);
        buf.append(" ");
        buf.append(pathTo);
        // System.out.println(buf.toString());
        execCommand(buf.toString());
    }

    // 关闭session
    public void closeSession() {
        if (session != null) {
            session.disconnect();
        }
    }

    public static void main(String[] args) {

        JschUtilRe jr = JschUtilRe.getInstance("zhou", "127.0.0.1", "xxxxxx");
        String resutlt = jr.execCommand("$HOME/.bash_profile;sh  /zhou/work/test.sh","gbk");
        jr.closeSession();
        System.out.println("resutlt = " + resutlt);

    }
}

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Java处理SSH 的相关文章

随机推荐

  • C++小白课本练习4

    练习目录 ConsoleApplication1 h 头文件定义类 Student myDate Student 类 myDate 类 第二章课本测试3验证类功能的驱动程序 cpp 第二章课本测试4使用指针的方式驱动程序 cpp 第二章课本
  • mysql数据库中文乱码的问题

    今天下午 在Qt中往mysql数据库中插入数据时 中文显示乱码 如下图所示 开始以为是数据库字符编码的问题 1 使用set character set database utf8 在命令行上修改字符编码 但是重启mysql之后 字符编码并没
  • Centos7系统防火墙使用教程【详解】

    CentOS 7是一种常见的Linux操作系统 防火墙作为网络安全的第一道防线 对于服务器的安全至关重要 本文将介绍CentOS 7系统中防火墙的使用教程 包括如何开启 关闭 配置以及防火墙规则的添加和删除 一 查看防火墙状态 在开始操作之
  • 关于Android Service真正的完全详解,你需要知道的一切

    Service全部内容基本会在本篇涉及到 我们将围绕以下主要知识点进行分析 Service简单概述 Service在清单文件中的声明 Service启动服务实现方式及其详解 Service绑定服务的三种实现方式 关于启动服务与绑定服务间的转
  • Verilog--CDC跨时钟域处理(快时钟域到慢时钟域)

    Verilog CDC跨时钟域处理 快时钟域到慢时钟域 CDC问题 单比特信号的跨时钟域问题 从快时钟域到慢时钟域 从慢时钟域到快时钟域 多比特信号的跨时钟域问题 异步FIFO 握手协议 DMUX 格雷码 双D触发器 今天先写单比特信号从快
  • 开始前准备

    开始前准备 一 环境预览 二 安装Ubuntu 三 安装arm gcc工具链 四 Ubuntu构建LiteOS所需要的工具链 五 安装STM32CubeMX软件 六 串口调试助手下载 七 ST Link和USB转TTL串口调试工具 一 环境
  • Express_2 Express Generator

    本文为课程笔记 总体来说 express generator可以帮助我们快速搭建一个express环境 首先 要将它安装在全局环境里 npm install express generator g 然后 就可以使用express 项目名 创
  • 数组入门练习:螺旋遍历二维数组

    NC38 螺旋矩阵 给出一个 n n n 行 m m m 列的二维数组 按螺旋的顺序返回矩阵中的所有元素 比如 输入为 1 2 3 4 5 6 7 8 9 输出为 1 2 3 6 9 8 7 4 5 观察上图
  • 关于mmsegmentation的自定义数据集格式的一些坑(2)

    这次又有任务要跑mmseg 我本意是拒绝的 奈何老板喜欢 mm系列的东西 那一套流程 真心玩不转 玩着玩着心就累了 mm系列和detectron差不多 要找其代码流转 都是要先看配置文件 比较麻烦 需要一定的经验 然后前面两篇都写了我是怎么
  • Android SELinux

    Google参考链接 https source android com docs core architecture aidl aidl hals sepolicy A 通信框架SE文件修改 public attributes vendor
  • 【canal系】canal集群异常Could not find first log file name in binary log index file

    这里先说明下这边使用的canal版本号为1 1 5 在描述这个问题之前 首先需要简单对于canal架构有个基本的了解 canal工作原理 canal 模拟 MySQL slave 的交互协议 伪装自己为 MySQL slave 向 MySQ
  • 详解@Override注解

    目录 1 是什么 2 为什么用 3 举例说明 1 示例一 2 示例二 3 示例三 1 是什么 Override注解是伪代码 用于表示被标注的方法是一个重写方法 Override注解 只能用于标记方法 并且它只在编译期生效 不会保留在clas
  • QT中添加Q_OBJECT出现的问题

    Multiple Inheritance Requires QObject to Be First 多重继承QObject一定要放在前面 我在用class My Node public QGraphicsItem public QObjec
  • 产业互联网-构建智能+时代数字生态新图景

    在2019腾讯全球数字生态大会新闻发布会上 腾讯云联合腾讯研究院 共同发布了行业重磅报告 产业互联网 构建智能 时代数字生态新图景 报告首次阐述了产业互联网的战略框架和实践方法论 报告指出 产业互联网的实现 需要跨界共建数字生态共同体 形成
  • linux安装telnet工具下载,Linux下安装telnet的方法

    一 安装telnet 1 检测telnet server的rpm包是否安装 root localhost rpm qa telnet server 若无输入内容 则表示没有安装 出于安全考虑telnet server rpm是默认没有安装的
  • NestedScrolling机制(一)——概述

    http blog csdn net al4fun article details 53888990 如今 NestedScrolling机制 可以称为嵌套滚动或嵌套滑动 在各种app中的应用已经十分广泛了 下图是 饿了么 中的一个例子 当
  • 虹膜识别 Iris_Osiris_v4.1源码,mfc测试用例

    01 资源 win10 vs2015 git opencv3 3 0 cmake 参考虹膜识别文档 开源虹膜识别软件OSIRIS4 1的使用入门 将开源虹膜识别算法OSIRIS4 1移植到Windows opencv3 3 0的配置参考 也
  • Leetcode 202. 快乐数(找规律注意回环)

    快乐数 编写一个算法来判断一个数 n 是不是快乐数 快乐数 定义为 对于一个正整数 每一次将该数替换为它每个位置上的数字的平方和 然后重复这个过程直到这个数变为 1 也可能是 无限循环 但始终变不到 1 如果 可以变为 1 那么这个数就是快
  • 记录几个CentOS安装包(rpm)的下载地址-离线安装必备

    1 http rpmfind net linux RPM index html 2 https centos pkgs org 3 http mirror centos org centos 7 extras x86 64 Packages
  • Java处理SSH

    JSch 登录 密码方式 session setPassword password 公私秘钥方式 jsch addIdentity ssh id rsaxxx SFTP简介 SFTP是Secure File Transfer Protoco