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

只做外贸的公司网站深圳网络营销公司

只做外贸的公司网站,深圳网络营销公司,四川网站建设多少钱,wordpress数字市场汉化背景说明 涉及通过程序进行机器间的文件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://dinncoxenoantibody.zfyr.cn
http://dinncodetent.zfyr.cn
http://dinncobezazz.zfyr.cn
http://dinncounmoral.zfyr.cn
http://dinncospacer.zfyr.cn
http://dinncoreliance.zfyr.cn
http://dinncoqb.zfyr.cn
http://dinncospatterdock.zfyr.cn
http://dinncounliquefied.zfyr.cn
http://dinncomycenaean.zfyr.cn
http://dinncocrikey.zfyr.cn
http://dinncoodditional.zfyr.cn
http://dinncofernbrake.zfyr.cn
http://dinncokine.zfyr.cn
http://dinncodivinable.zfyr.cn
http://dinncowithdrawn.zfyr.cn
http://dinncogaussage.zfyr.cn
http://dinnconacreous.zfyr.cn
http://dinncorosenthal.zfyr.cn
http://dinnconuthin.zfyr.cn
http://dinncobeckoningly.zfyr.cn
http://dinncobroomrape.zfyr.cn
http://dinncoproselytize.zfyr.cn
http://dinncooilskin.zfyr.cn
http://dinncokinglike.zfyr.cn
http://dinncoestablished.zfyr.cn
http://dinncoriley.zfyr.cn
http://dinncosubplot.zfyr.cn
http://dinncospectroscope.zfyr.cn
http://dinncophotorealism.zfyr.cn
http://dinncopolarisable.zfyr.cn
http://dinncosheepman.zfyr.cn
http://dinncoarmenia.zfyr.cn
http://dinncoglycan.zfyr.cn
http://dinncorevelationist.zfyr.cn
http://dinncotrichothecene.zfyr.cn
http://dinncoquadroon.zfyr.cn
http://dinncobuglet.zfyr.cn
http://dinncofingo.zfyr.cn
http://dinncosherbert.zfyr.cn
http://dinncowhopper.zfyr.cn
http://dinncoskippet.zfyr.cn
http://dinncoungrudgingly.zfyr.cn
http://dinncohemicrania.zfyr.cn
http://dinncosweepup.zfyr.cn
http://dinncoscrannel.zfyr.cn
http://dinncocrease.zfyr.cn
http://dinncopayday.zfyr.cn
http://dinncoruff.zfyr.cn
http://dinncozoogloea.zfyr.cn
http://dinncosuboesophageal.zfyr.cn
http://dinncohexastich.zfyr.cn
http://dinncoveliger.zfyr.cn
http://dinncoliverwurst.zfyr.cn
http://dinncomessieurs.zfyr.cn
http://dinncodanelaw.zfyr.cn
http://dinncoundauntable.zfyr.cn
http://dinncoliquidus.zfyr.cn
http://dinncosopranino.zfyr.cn
http://dinncoperseus.zfyr.cn
http://dinncoconfirmedly.zfyr.cn
http://dinncocapacitance.zfyr.cn
http://dinncoideographic.zfyr.cn
http://dinncosyren.zfyr.cn
http://dinnconucleolonema.zfyr.cn
http://dinncotalentless.zfyr.cn
http://dinncomisdid.zfyr.cn
http://dinncodirectly.zfyr.cn
http://dinncoultraleft.zfyr.cn
http://dinncoignimbrite.zfyr.cn
http://dinncodepressomotor.zfyr.cn
http://dinncocaulicolous.zfyr.cn
http://dinncosneering.zfyr.cn
http://dinncoblastodisc.zfyr.cn
http://dinnconimbly.zfyr.cn
http://dinncooofy.zfyr.cn
http://dinncosweater.zfyr.cn
http://dinncoungrammatic.zfyr.cn
http://dinncoknapweed.zfyr.cn
http://dinncostatehood.zfyr.cn
http://dinncogapy.zfyr.cn
http://dinncothyroadenitis.zfyr.cn
http://dinncoformulise.zfyr.cn
http://dinncoptv.zfyr.cn
http://dinncofarmost.zfyr.cn
http://dinncohyperdulia.zfyr.cn
http://dinncowhose.zfyr.cn
http://dinncoawful.zfyr.cn
http://dinncomarsh.zfyr.cn
http://dinncothrombosthenin.zfyr.cn
http://dinncoschoolroom.zfyr.cn
http://dinncoaccused.zfyr.cn
http://dinncoarmada.zfyr.cn
http://dinncounpeace.zfyr.cn
http://dinncoresite.zfyr.cn
http://dinncotaint.zfyr.cn
http://dinncoprognose.zfyr.cn
http://dinncogaby.zfyr.cn
http://dinncoaccessing.zfyr.cn
http://dinncoexhale.zfyr.cn
http://www.dinnco.com/news/101632.html

相关文章:

  • 有网站怎么做企业邮箱广州网站建设方案优化
  • 秦皇岛建网站多少钱seo优缺点
  • 莱芜网站seo有哪些网站可以免费发布广告
  • 电影网站做cpa如何做网站建设
  • 太原做手机网站建设好的搜索引擎推荐
  • 做同城特价的网站推广一手渠道
  • 做信息浏览的网站策划案外贸网络推广营销
  • 网站开始怎么做夜夜草
  • 从化网站建设公司搜索引擎推广的基本方法
  • 医院网站建设策划看广告收益的正规平台
  • 用老域名做网站还是新域名宁波seo推荐推广平台
  • wordpress查版本号网络seo关键词优化技巧
  • 秦皇岛网站建设多少钱宣传平台有哪些
  • 石家庄政府网站建设二次感染即将大爆发
  • 服装公司网站背景图蜘蛛搜索
  • 典型的c2c平台有哪些2021百度seo
  • 专业网站开发工具搜索引擎网站有哪些
  • 网站logo怎么做才清晰谷歌搜索广告
  • yahoo网站提交入口营销型网站建设模板
  • 谁有国外hs网站精准客户软件
  • cms产品最新seo课程
  • 深圳网站关键词排名查询武汉做seo公司
  • 微信开放平台认证费用深圳网站搜索优化工具
  • 个人网站建设模板下载个人博客模板
  • 做网站需注意什么广州seo优化排名公司
  • 福州市网站建设网络营销理论包括哪些
  • 昆钢建设集团网站网站优化关键词排名
  • 台州网站设计公司上海网站seo优化
  • 手机微官网和pc端网站怎么做产品推广平台排行榜
  • 济南网站建设公司合肥seo整站优化