当前位置: 首页 > news >正文

做网站公司怎么找最新国际新闻10条

做网站公司怎么找,最新国际新闻10条,网站 不 备案,甘肃省第九建设集团网站背景说明 涉及通过程序进行机器间的文件Copy的场景,我们一般会使用ssh连接机器,通过scp命令进行文件copy。 此种方案的前提是:机器间事先要配置免密码互通。 但是,如果客户现场机器数量过多,配置免密操作比较麻烦&a…

背景说明

涉及通过程序进行机器间的文件Copy的场景,我们一般会使用ssh连接机器,通过scp命令进行文件copy。

此种方案的前提是:机器间事先要配置免密码互通。

但是,如果客户现场机器数量过多,配置免密操作比较麻烦;或者处于安全考虑,客户不允许机器之间免密访问。

此时,需要另辟蹊径,找其他方案实现。

需求场景:提供机器的IP,登录用户名、登录密码,但是不配置机器间的免密登录,实现机器之间的文件传输。


Java 实现

1、工具类

ScpUtil.java

package com.miracle.luna.scp;import org.apache.sshd.client.SshClient;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.scp.client.ScpClient;
import org.apache.sshd.scp.client.ScpClientCreator;/*** @author Miracle Luna* @date 2021/7/19*/
public class ScpUtil {//    private static String host = "192.168.67.48";private static String host = "192.168.67.39";
//    private static String host = "192.168.71.29";private static String username = "root";private static String password = "password";private static Integer port = 22;//    private static String local = "F:\\miracle\\*";private static String local = "/home/miracle/*";private static String remote = "/home/luna/";
//    private static String remote = "F:\\luna\\";public static void scpFile(String local, String remote) throws Exception {long startTime = System.currentTimeMillis();// 创建 SSH客户端SshClient client = SshClient.setUpDefaultClient();// 启动 SSH客户端client.start();// 通过主机IP、端口和用户名,连接主机,获取SessionClientSession session = client.connect(username, host, port).verify().getSession();// 给Session添加密码session.addPasswordIdentity(password);// 校验用户名和密码的有效性boolean isSuccess = session.auth().verify().isSuccess();// 认证成功if (isSuccess) {long middleTime = System.currentTimeMillis();System.out.println("Connect host cost time: " + (middleTime - startTime) / 1000.0 + "s.");ScpClientCreator creator = ScpClientCreator.instance();// 创建 SCP 客户端ScpClient scpClient = creator.createScpClient(session);System.out.println("Scp beginning.");// ScpClient.Option.Recursive:递归copy,可以将子文件夹和子文件遍历copyscpClient.upload(local, remote, ScpClient.Option.Recursive);System.out.println("Scp finished.");// 释放 SCP客户端if (scpClient != null) {scpClient = null;}// 关闭 Sessionif (session != null && session.isOpen()) {session.close();}// 关闭 SSH客户端if (client != null && client.isOpen()) {client.stop();client.close();}}long endTime = System.currentTimeMillis();System.out.println("Total Cost time: " + (endTime - startTime) / 1000.0 + "s.");}public static void main(String[] args) throws Exception {scpFile(local, remote);}
}

2、运行结果

Connect host cost time: 6.519s.
Scp beginning.
Scp finished.
Total Cost time: 9.569s.

3、Maven依赖

<!-- https://mvnrepository.com/artifact/org.apache.sshd/sshd-common -->
<dependency><groupId>org.apache.sshd</groupId><artifactId>sshd-common</artifactId><version>2.7.0</version>
</dependency><!-- https://mvnrepository.com/artifact/org.apache.sshd/sshd-core -->
<dependency><groupId>org.apache.sshd</groupId><artifactId>sshd-core</artifactId><version>2.7.0</version>
</dependency><!-- https://mvnrepository.com/artifact/org.apache.sshd/sshd-scp -->
<dependency><groupId>org.apache.sshd</groupId><artifactId>sshd-scp</artifactId><version>2.7.0</version>
</dependency>

补充说明

该方式适用于Linux到Linux、Linux到Windows、Windows到Linux、Windows到Windows间的文件拷贝。

(和Windows进行文件交互的前提是:Windows安装了SSH服务端,如OpenSSH,FreeSSHd,Bitvise SSH Server等)


http://www.mnyf.cn/news/45025.html

相关文章:

  • 做网站 传视频 用什么笔记本好seo排名推广工具
  • 昆明专业的网站制作建设洛阳网站建设优化
  • ps做网站设计最近五天的新闻大事
  • 免费自学平面设计的网站西安网站建设方案优化
  • 新网站做百度推广 收录如何推销产品给客户
  • 个人备案域名做企业网站漯河网站推广公司
  • 南昌本地生活网站有哪些北京优化网站方法
  • 湖南常德最新疫情最新消息广州网站优化方案
  • wordpress设置自己的管理邮箱win7一键优化工具
  • WordPress主题MX互动网站优化公司哪家效果好
  • 网页设计 网站建设 哪个好上海seo优化服务公司
  • 调查队网站建设如何网络推广新产品
  • 外贸网站如何制作厦门网站建设公司
  • 浏览国外服务器的网站博客是哪个软件
  • 万江仿做网站广州google推广
  • 沈阳品牌网站建设百度经验app
  • 南通营销平台网站建设b2b平台有哪些网站
  • 重庆建设教育培训管理系统福建seo网站
  • 一分钟用自己的电脑做网站搜索引擎优化策略
  • wordpress 4.0 打开慢seo引擎优化服务
  • 学校网站模板 dedecms微营销平台
  • 访问不了网站目录中的网页拼多多seo 优化软件
  • 商业网站建设案例课程推广普通话演讲稿
  • 网站建设业务客户来源百度竞价排名案例分析
  • 怎么把网站改为正在建设中国产最好的a级suv88814
  • 中山网站建设找阿 n 2外贸推广方式
  • 怎么可以做自己的网站如何自己做一个软件
  • 嘉兴门户网站优化推广网站排名
  • 域名如何解绑一个网站百度应用市场
  • 大理石在哪些网站做宣传一级消防工程师考试