Apache MINA SSHD

2024-04-10 07:20
文章标签 apache mina sshd

本文主要是介绍Apache MINA SSHD,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

      

目录

1.远程登录

1.1密码登录

1.2密钥登录

2.执行命令

2.1 ChannelExec

2.2 ChannelShell

3.文件传输

 3.1 上传文件

3.2 下载文件

3.3 SftpFileSystem


       Apache MINA SSHD(Secure Shell Daemon)是基于Apache MINA(Multipurpose Infrastructure for Network Applications)开发的一个开源的Java库,专门用于提供SSH(Secure Shell)服务。SSH是一种网络协议,用于在不安全的网络环境中进行安全通信和远程操作:主要用于远程登录、文件传输、以及安全的命令执行等场景。

1.远程登录

1.1密码登录

package com.yichenkeji.starter.ssh;import lombok.extern.slf4j.Slf4j;
import org.apache.sshd.client.SshClient;
import org.apache.sshd.client.channel.ChannelExec;
import org.apache.sshd.client.channel.ChannelShell;
import org.apache.sshd.client.channel.ClientChannelEvent;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.sftp.client.SftpClientFactory;
import org.apache.sshd.sftp.client.fs.SftpFileSystem;import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.util.EnumSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;/*** Sshd工具类*/
@Slf4j
public class SshdTest {private SshClient client;private ClientSession session;public static void main(String[] args) throws Exception {}/*** 连接* @param host* @param port* @param username*/private void connect(String host, int port, String username)  {client = SshClient.setUpDefaultClient();client.start();try  {session = client.connect(username, host, port).verify(5000).getSession();} catch (IOException e) {throw new RuntimeException(e);}}/*** 密码登录* @param host* @param port* @param username* @param password*/public SshdTest(String host, int port, String username, String password) {connect(host,port,username);try  {session.addPasswordIdentity(password); // for password-based authenticationif (session.auth().verify(5000).isFailure()) {throw new RuntimeException("验证失败");}} catch (IOException e) {throw new RuntimeException(e);}}/*** 关闭连接*/public void close(){log.info("关闭 SSH");closeSession();if(client != null){try {client.close();} catch (IOException e) {log.error(e.getMessage());}}}private void closeSession() {if(session != null){try {session.close();} catch (IOException e) {log.error(e.getMessage());}}}
}

1.2密钥登录

package com.yichenkeji.starter.ssh;import lombok.extern.slf4j.Slf4j;
import org.apache.sshd.client.SshClient;
import org.apache.sshd.client.channel.ChannelExec;
import org.apache.sshd.client.channel.ChannelShell;
import org.apache.sshd.client.channel.ClientChannelEvent;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.sftp.client.SftpClientFactory;
import org.apache.sshd.sftp.client.fs.SftpFileSystem;import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.util.EnumSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;/*** Sshd工具类*/
@Slf4j
public class SshdTest {private SshClient client;private ClientSession session;public static void main(String[] args) throws Exception {}/*** 连接* @param host* @param port* @param username*/private void connect(String host, int port, String username)  {client = SshClient.setUpDefaultClient();client.start();try  {session = client.connect(username, host, port).verify(5000).getSession();} catch (IOException e) {throw new RuntimeException(e);}}/*** 密钥登录* @param host* @param port* @param username*/public SshdTest(String host, int port, String username) {connect(host,port,username);try  {String privateKeyPath = System.getProperty("user.home") + "/.ssh/id_rsa";String privateKeyContent = new String(Files.readAllBytes(Paths.get(privateKeyPath)));//获取密钥对KeyPairGenerator rsa = KeyPairGenerator.getInstance("RSA");KeyPair keyPair = rsa.generateKeyPair();ByteArrayOutputStream stream = new ByteArrayOutputStream();stream.write(privateKeyContent.getBytes());ObjectOutputStream o = new ObjectOutputStream(stream);o.writeObject(keyPair);session.addPublicKeyIdentity(keyPair);if (session.auth().verify(5000).isFailure()) {throw new RuntimeException("验证失败");}} catch (Exception e) {throw new RuntimeException(e);}}/*** 关闭连接*/public void close(){log.info("关闭 SSH");closeSession();if(client != null){try {client.close();} catch (IOException e) {log.error(e.getMessage());}}}private void closeSession() {if(session != null){try {session.close();} catch (IOException e) {log.error(e.getMessage());}}}
}

2.执行命令

2.1 ChannelExec

        ChannelExec是Apache Mina SSHD中的一个类,它提供了一种在SSH连接上执行远程命令的方式,以及处理命令输入、输出、参数和状态的能力。它灵活性高、可扩展性强,适用于需要与远程服务器进行命令交互和执行的场景。

package com.yichenkeji.starter.ssh;import lombok.extern.slf4j.Slf4j;
import org.apache.sshd.client.SshClient;
import org.apache.sshd.client.channel.ChannelExec;
import org.apache.sshd.client.channel.ChannelShell;
import org.apache.sshd.client.channel.ClientChannelEvent;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.sftp.client.SftpClient;
import org.apache.sshd.sftp.client.SftpClientFactory;
import org.apache.sshd.sftp.client.fs.SftpFileSystem;import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.util.EnumSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;/*** Sshd工具类*/
@Slf4j
public class SshdTest {private SshClient client;private ClientSession session;public static void main(String[] args) throws Exception {SshdTest sshUtil = new SshdTest("192.168.179.131",22,"weisx","123456");sshUtil.execCommand("pwd");}/*** 连接* @param host* @param port* @param username*/private void connect(String host, int port, String username)  {client = SshClient.setUpDefaultClient();client.start();try  {session = client.connect(username, host, port).verify(5000).getSession();} catch (IOException e) {throw new RuntimeException(e);}}/*** 密码登录* @param host* @param port* @param username* @param password*/public SshdTest(String host, int port, String username, String password) {connect(host,port,username);try  {session.addPasswordIdentity(password); // for password-based authenticationif (session.auth().verify(5000).isFailure()) {throw new RuntimeException("验证失败");}} catch (IOException e) {throw new RuntimeException(e);}}/*** 密钥登录* @param host* @param port* @param username*/public SshdTest(String host, int port, String username) {connect(host,port,username);try  {String privateKeyPath = System.getProperty("user.home") + "/.ssh/id_rsa";String privateKeyContent = new String(Files.readAllBytes(Paths.get(privateKeyPath)));//获取密钥对KeyPairGenerator rsa = KeyPairGenerator.getInstance("RSA");KeyPair keyPair = rsa.generateKeyPair();ByteArrayOutputStream stream = new ByteArrayOutputStream();stream.write(privateKeyContent.getBytes());ObjectOutputStream o = new ObjectOutputStream(stream);o.writeObject(keyPair);session.addPublicKeyIdentity(keyPair);if (session.auth().verify(5000).isFailure()) {throw new RuntimeException("验证失败");}} catch (Exception e) {throw new RuntimeException(e);}}/*** 执行命令* @param command* @return*/public String execCommand(String command){session.resetAuthTimeout();System.out.println("exe cmd: "+ command);// 返回结果流ByteArrayOutputStream out = new ByteArrayOutputStream();// 错误信息ByteArrayOutputStream err = new ByteArrayOutputStream();try(ChannelExec channelExec = session.createExecChannel(command)) {channelExec.setOut(out);channelExec.setErr(err);// 执行并等待channelExec.open();Set<ClientChannelEvent> events =channelExec.waitFor(EnumSet.of(ClientChannelEvent.CLOSED),TimeUnit.SECONDS.toMillis(100000));// 检查请求是否超时if (events.contains(ClientChannelEvent.TIMEOUT)) {throw new RuntimeException("请求连接超时");}// 一般退出状态为0表示正常int exitStatus = channelExec.getExitStatus();if (exitStatus == 1) {log.info("exitStatus:{}",exitStatus);
//				throw new RuntimeException("执行命令失败:"+exitStatus);}} catch (Exception e) {throw new RuntimeException(e);}return out.toString().trim();}/*** 关闭连接*/public void close(){log.info("关闭 SSH");closeSession();if(client != null){try {client.close();} catch (IOException e) {log.error(e.getMessage());}}}private void closeSession() {if(session != null){try {session.close();} catch (IOException e) {log.error(e.getMessage());}}}
}

2.2 ChannelShell

        ChannelShell是Apache Mina SSHD中的一个用于使用交互式shell的类,它提供了在远程服务器上执行交互式命令和脚本,并与其进行实时交互的功能。与 ChannelExec 相比,可以更灵活地与远程服务器进行交互和执行复杂的命令。

package com.yichenkeji.starter.ssh;import lombok.extern.slf4j.Slf4j;
import org.apache.sshd.client.SshClient;
import org.apache.sshd.client.channel.ChannelExec;
import org.apache.sshd.client.channel.ChannelShell;
import org.apache.sshd.client.channel.ClientChannelEvent;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.sftp.client.SftpClient;
import org.apache.sshd.sftp.client.SftpClientFactory;
import org.apache.sshd.sftp.client.fs.SftpFileSystem;import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.util.EnumSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;/*** Sshd工具类*/
@Slf4j
public class SshdTest {private SshClient client;private ClientSession session;public static void main(String[] args) throws Exception {SshdTest sshUtil = new SshdTest("192.168.179.131",22,"weisx","123456");String[] commends ={"pwd","cd ","pwd"};sshUtil.execCommand(commends);}/*** 连接* @param host* @param port* @param username*/private void connect(String host, int port, String username)  {client = SshClient.setUpDefaultClient();client.start();try  {session = client.connect(username, host, port).verify(5000).getSession();} catch (IOException e) {throw new RuntimeException(e);}}/*** 密码登录* @param host* @param port* @param username* @param password*/public SshdTest(String host, int port, String username, String password) {connect(host,port,username);try  {session.addPasswordIdentity(password); // for password-based authenticationif (session.auth().verify(5000).isFailure()) {throw new RuntimeException("验证失败");}} catch (IOException e) {throw new RuntimeException(e);}}/*** 密钥登录* @param host* @param port* @param username*/public SshdTest(String host, int port, String username) {connect(host,port,username);try  {String privateKeyPath = System.getProperty("user.home") + "/.ssh/id_rsa";String privateKeyContent = new String(Files.readAllBytes(Paths.get(privateKeyPath)));//获取密钥对KeyPairGenerator rsa = KeyPairGenerator.getInstance("RSA");KeyPair keyPair = rsa.generateKeyPair();ByteArrayOutputStream stream = new ByteArrayOutputStream();stream.write(privateKeyContent.getBytes());ObjectOutputStream o = new ObjectOutputStream(stream);o.writeObject(keyPair);session.addPublicKeyIdentity(keyPair);if (session.auth().verify(5000).isFailure()) {throw new RuntimeException("验证失败");}} catch (Exception e) {throw new RuntimeException(e);}}/*** 执行命令* @param commands* @return*/public String execCommand(String[] commands){session.resetAuthTimeout();System.out.println("exe cmd: "+ String.join(";",commands));// 命令返回的结果StringBuffer resultBuf = new StringBuffer("");try (ChannelShell channel = session.createShellChannel()) {channel.open().verify(5 , TimeUnit.SECONDS);// 执行命令try (PrintStream out = new PrintStream(channel.getInvertedIn())) {for (String command:commands){out.println(command);out.flush();}out.println("exit");out.flush();}//channel.waitFor(Collections.singleton(ClientChannelEvent.CLOSED), 0);try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(channel.getInvertedOut()))) {String line;while ((line = bufferedReader.readLine()) != null) {System.out.println(line);resultBuf.append(line);}}} catch (IOException e) {throw new RuntimeException(e);}return resultBuf.toString().trim();}/*** 关闭连接*/public void close(){log.info("关闭 SSH");closeSession();if(client != null){try {client.close();} catch (IOException e) {log.error(e.getMessage());}}}private void closeSession() {if(session != null){try {session.close();} catch (IOException e) {log.error(e.getMessage());}}}
}

3.文件传输

        SftpClient是基于Apache MINA SSHD库的一个SFTP(SSH File Transfer Protocol)客户端实现,它提供了一套方便且易于使用的API,用于在Java应用程序中与远程SFTP服务器进行文件传输和管理。

 3.1 上传文件

package com.yichenkeji.starter.ssh;import lombok.extern.slf4j.Slf4j;
import org.apache.sshd.client.SshClient;
import org.apache.sshd.client.channel.ChannelExec;
import org.apache.sshd.client.channel.ChannelShell;
import org.apache.sshd.client.channel.ClientChannelEvent;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.sftp.client.SftpClient;
import org.apache.sshd.sftp.client.SftpClientFactory;
import org.apache.sshd.sftp.client.fs.SftpFileSystem;
import org.apache.sshd.sftp.client.fs.SftpPath;import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.PosixFilePermissions;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;/*** Sshd工具类** https://github.com/apache/mina-sshd/blob/master/docs/sftp.md*/
@Slf4j
public class SshdTest {private SshClient client;private ClientSession session;public static void main(String[] args) throws Exception {SshdTest sshUtil = new SshdTest("192.168.179.131",22,"weisx","123456");sshUtil.uploadFile(new File("F:\\24\\tmp.txt"),"/home/weisx/");}/*** 连接* @param host* @param port* @param username*/private void connect(String host, int port, String username)  {client = SshClient.setUpDefaultClient();client.start();try  {session = client.connect(username, host, port).verify(5000).getSession();} catch (IOException e) {throw new RuntimeException(e);}}/*** 密码登录* @param host* @param port* @param username* @param password*/public SshdTest(String host, int port, String username, String password) {connect(host,port,username);try  {session.addPasswordIdentity(password); // for password-based authenticationif (session.auth().verify(5000).isFailure()) {throw new RuntimeException("验证失败");}} catch (IOException e) {throw new RuntimeException(e);}}/*** 密钥登录* @param host* @param port* @param username*/public SshdTest(String host, int port, String username) {connect(host,port,username);try  {String privateKeyPath = System.getProperty("user.home") + "/.ssh/id_rsa";String privateKeyContent = new String(Files.readAllBytes(Paths.get(privateKeyPath)));//获取密钥对KeyPairGenerator rsa = KeyPairGenerator.getInstance("RSA");KeyPair keyPair = rsa.generateKeyPair();ByteArrayOutputStream stream = new ByteArrayOutputStream();stream.write(privateKeyContent.getBytes());ObjectOutputStream o = new ObjectOutputStream(stream);o.writeObject(keyPair);session.addPublicKeyIdentity(keyPair);if (session.auth().verify(5000).isFailure()) {throw new RuntimeException("验证失败");}} catch (Exception e) {throw new RuntimeException(e);}}/*** 上传文件* @param uploadFile 上传的文件* @param remotePath 远程目录*/public  String uploadFile(File uploadFile,String remotePath) {try(SftpClient  sftpClient = SftpClientFactory.instance().createSftpClient(session);OutputStream outputStream = sftpClient.write(remotePath)) {Files.copy(uploadFile.toPath(), outputStream);return remotePath;} catch (IOException e) {throw new RuntimeException(e);}}/*** 关闭连接*/public void close(){log.info("关闭 SSH");closeSession();if(client != null){try {client.close();} catch (IOException e) {log.error(e.getMessage());}}}private void closeSession() {if(session != null){try {session.close();} catch (IOException e) {log.error(e.getMessage());}}}
}

3.2 下载文件

package com.yichenkeji.starter.ssh;import lombok.extern.slf4j.Slf4j;
import org.apache.sshd.client.SshClient;
import org.apache.sshd.client.channel.ChannelExec;
import org.apache.sshd.client.channel.ChannelShell;
import org.apache.sshd.client.channel.ClientChannelEvent;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.sftp.client.SftpClient;
import org.apache.sshd.sftp.client.SftpClientFactory;
import org.apache.sshd.sftp.client.fs.SftpFileSystem;
import org.apache.sshd.sftp.client.fs.SftpPath;import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.PosixFilePermissions;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;/*** Sshd工具类** https://github.com/apache/mina-sshd/blob/master/docs/sftp.md*/
@Slf4j
public class SshdTest {private SshClient client;private ClientSession session;public static void main(String[] args) throws Exception {SshdTest sshUtil = new SshdTest("192.168.179.131",22,"weisx","123456");sshUtil.downloadFile("/home/weisx/tmp.txt","F:\\24\\");}/*** 连接* @param host* @param port* @param username*/private void connect(String host, int port, String username)  {client = SshClient.setUpDefaultClient();client.start();try  {session = client.connect(username, host, port).verify(5000).getSession();} catch (IOException e) {throw new RuntimeException(e);}}/*** 密码登录* @param host* @param port* @param username* @param password*/public SshdTest(String host, int port, String username, String password) {connect(host,port,username);try  {session.addPasswordIdentity(password); // for password-based authenticationif (session.auth().verify(5000).isFailure()) {throw new RuntimeException("验证失败");}} catch (IOException e) {throw new RuntimeException(e);}}/*** 密钥登录* @param host* @param port* @param username*/public SshdTest(String host, int port, String username) {connect(host,port,username);try  {String privateKeyPath = System.getProperty("user.home") + "/.ssh/id_rsa";String privateKeyContent = new String(Files.readAllBytes(Paths.get(privateKeyPath)));//获取密钥对KeyPairGenerator rsa = KeyPairGenerator.getInstance("RSA");KeyPair keyPair = rsa.generateKeyPair();ByteArrayOutputStream stream = new ByteArrayOutputStream();stream.write(privateKeyContent.getBytes());ObjectOutputStream o = new ObjectOutputStream(stream);o.writeObject(keyPair);session.addPublicKeyIdentity(keyPair);if (session.auth().verify(5000).isFailure()) {throw new RuntimeException("验证失败");}} catch (Exception e) {throw new RuntimeException(e);}}/*** 下载文件* @param remoteFilePath 下载的文件* @param savePath 保存的目录*/public  void downloadFile(String remoteFilePath,String savePath) {try(SftpClient  sftpClient = SftpClientFactory.instance().createSftpClient(session);InputStream inputStream = sftpClient.read(remoteFilePath)) {File destFile = new File(savePath);Files.copy(inputStream , destFile.toPath() , StandardCopyOption.REPLACE_EXISTING);} catch (IOException e) {throw new RuntimeException(e);}}/*** 关闭连接*/public void close(){log.info("关闭 SSH");closeSession();if(client != null){try {client.close();} catch (IOException e) {log.error(e.getMessage());}}}private void closeSession() {if(session != null){try {session.close();} catch (IOException e) {log.error(e.getMessage());}}}
}

3.3 SftpFileSystem

        SftpFileSystem是Apache Mina SSHD中实现的基于VFS框架的SFTP文件系统,它供了一套统一的API和一些额外的高级功能,方便用户访问和操作远程文件系统,适用于复杂的文件系统操作和要求更高级功能的场景。

package com.yichenkeji.starter.ssh;import lombok.extern.slf4j.Slf4j;
import org.apache.sshd.client.SshClient;
import org.apache.sshd.client.channel.ChannelExec;
import org.apache.sshd.client.channel.ChannelShell;
import org.apache.sshd.client.channel.ClientChannelEvent;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.sftp.client.SftpClient;
import org.apache.sshd.sftp.client.SftpClientFactory;
import org.apache.sshd.sftp.client.fs.SftpFileSystem;
import org.apache.sshd.sftp.client.fs.SftpPath;import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.PosixFilePermissions;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;/*** Sshd工具类** https://github.com/apache/mina-sshd/blob/master/docs/sftp.md*/
@Slf4j
public class SshdTest {private SshClient client;private ClientSession session;public static void main(String[] args) throws Exception {SshdTest sshUtil = new SshdTest("192.168.179.131",22,"weisx","123456");sshUtil.fileMeta("/home/weisx/tmp.txt");}/*** 连接* @param host* @param port* @param username*/private void connect(String host, int port, String username)  {client = SshClient.setUpDefaultClient();client.start();try  {session = client.connect(username, host, port).verify(5000).getSession();} catch (IOException e) {throw new RuntimeException(e);}}/*** 密码登录* @param host* @param port* @param username* @param password*/public SshdTest(String host, int port, String username, String password) {connect(host,port,username);try  {session.addPasswordIdentity(password); // for password-based authenticationif (session.auth().verify(5000).isFailure()) {throw new RuntimeException("验证失败");}} catch (IOException e) {throw new RuntimeException(e);}}/*** 密钥登录* @param host* @param port* @param username*/public SshdTest(String host, int port, String username) {connect(host,port,username);try  {String privateKeyPath = System.getProperty("user.home") + "/.ssh/id_rsa";String privateKeyContent = new String(Files.readAllBytes(Paths.get(privateKeyPath)));//获取密钥对KeyPairGenerator rsa = KeyPairGenerator.getInstance("RSA");KeyPair keyPair = rsa.generateKeyPair();ByteArrayOutputStream stream = new ByteArrayOutputStream();stream.write(privateKeyContent.getBytes());ObjectOutputStream o = new ObjectOutputStream(stream);o.writeObject(keyPair);session.addPublicKeyIdentity(keyPair);if (session.auth().verify(5000).isFailure()) {throw new RuntimeException("验证失败");}} catch (Exception e) {throw new RuntimeException(e);}}/*** 获取文件信息* @param filePath 文件路径*/public  void fileMeta(String filePath) {try(SftpFileSystem sftp = SftpClientFactory.instance().createSftpFileSystem(session)) {SftpPath path = sftp.getPath(filePath);System.out.println("文件名:" + path.getFileName());System.out.println("文件大小:" + Files.size(path));System.out.println("最后更新时间:" + Files.getLastModifiedTime(path));//如果是目录,则可以列出目录下全部文件try (Stream<Path> stream = Files.list(path)) {List<Path> paths = stream.collect(Collectors.toList());for (Path p : paths) {if (Files.isDirectory(p)) {System.out.println("文件夹:" + p.getFileName());} else {System.out.println("文件:  " + p.getFileName());}}}} catch (IOException e) {throw new RuntimeException(e);}}/*** 关闭连接*/public void close(){log.info("关闭 SSH");closeSession();if(client != null){try {client.close();} catch (IOException e) {log.error(e.getMessage());}}}private void closeSession() {if(session != null){try {session.close();} catch (IOException e) {log.error(e.getMessage());}}}
}

这篇关于Apache MINA SSHD的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/890406

相关文章

SpringBoot整合Apache Flink的详细指南

《SpringBoot整合ApacheFlink的详细指南》这篇文章主要为大家详细介绍了SpringBoot整合ApacheFlink的详细过程,涵盖环境准备,依赖配置,代码实现及运行步骤,感兴趣的... 目录1. 背景与目标2. 环境准备2.1 开发工具2.2 技术版本3. 创建 Spring Boot

Linux中修改Apache HTTP Server(httpd)默认端口的完整指南

《Linux中修改ApacheHTTPServer(httpd)默认端口的完整指南》ApacheHTTPServer(简称httpd)是Linux系统中最常用的Web服务器之一,本文将详细介绍如何... 目录一、修改 httpd 默认端口的步骤1. 查找 httpd 配置文件路径2. 编辑配置文件3. 保存

Spring Boot 整合 Apache Flink 的详细过程

《SpringBoot整合ApacheFlink的详细过程》ApacheFlink是一个高性能的分布式流处理框架,而SpringBoot提供了快速构建企业级应用的能力,下面给大家介绍Spri... 目录Spring Boot 整合 Apache Flink 教程一、背景与目标二、环境准备三、创建项目 & 添

Apache 高级配置实战之从连接保持到日志分析的完整指南

《Apache高级配置实战之从连接保持到日志分析的完整指南》本文带你从连接保持优化开始,一路走到访问控制和日志管理,最后用AWStats来分析网站数据,对Apache配置日志分析相关知识感兴趣的朋友... 目录Apache 高级配置实战:从连接保持到日志分析的完整指南前言 一、Apache 连接保持 - 性

apache的commons-pool2原理与使用实践记录

《apache的commons-pool2原理与使用实践记录》ApacheCommonsPool2是一个高效的对象池化框架,通过复用昂贵资源(如数据库连接、线程、网络连接)优化系统性能,这篇文章主... 目录一、核心原理与组件二、使用步骤详解(以数据库连接池为例)三、高级配置与优化四、典型应用场景五、注意事

解决Maven项目报错:failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.13.0的问题

《解决Maven项目报错:failedtoexecutegoalorg.apache.maven.plugins:maven-compiler-plugin:3.13.0的问题》这篇文章主要介... 目录Maven项目报错:failed to execute goal org.apache.maven.pl

深入理解Apache Kafka(分布式流处理平台)

《深入理解ApacheKafka(分布式流处理平台)》ApacheKafka作为现代分布式系统中的核心中间件,为构建高吞吐量、低延迟的数据管道提供了强大支持,本文将深入探讨Kafka的核心概念、架构... 目录引言一、Apache Kafka概述1.1 什么是Kafka?1.2 Kafka的核心概念二、Ka

使用Apache POI在Java中实现Excel单元格的合并

《使用ApachePOI在Java中实现Excel单元格的合并》在日常工作中,Excel是一个不可或缺的工具,尤其是在处理大量数据时,本文将介绍如何使用ApachePOI库在Java中实现Excel... 目录工具类介绍工具类代码调用示例依赖配置总结在日常工作中,Excel 是一个不可或缺的工http://

Apache伪静态(Rewrite).htaccess文件详解与配置技巧

《Apache伪静态(Rewrite).htaccess文件详解与配置技巧》Apache伪静态(Rewrite).htaccess是一个纯文本文件,它里面存放着Apache服务器配置相关的指令,主要的... 一、.htAccess的基本作用.htaccess是一个纯文本文件,它里面存放着Apache服务器

Debezium 与 Apache Kafka 的集成方式步骤详解

《Debezium与ApacheKafka的集成方式步骤详解》本文详细介绍了如何将Debezium与ApacheKafka集成,包括集成概述、步骤、注意事项等,通过KafkaConnect,D... 目录一、集成概述二、集成步骤1. 准备 Kafka 环境2. 配置 Kafka Connect3. 安装 D