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

微网站如何做横幅链接网站排名优化需要多久

微网站如何做横幅链接,网站排名优化需要多久,如何制作个人作品网站,微信公众号官网登录入口手机版java远程连接Linux执行命令的三种方式 1. 使用JDK自带的RunTime类和Process类实现2. ganymed-ssh2 实现3. jsch实现4. 完整代码:执行shell命令下载和上传文件 1. 使用JDK自带的RunTime类和Process类实现 public static void main(String[] args){Process proc Run…

java远程连接Linux执行命令的三种方式

  • 1. 使用JDK自带的RunTime类和Process类实现
  • 2. ganymed-ssh2 实现
  • 3. jsch实现
  • 4. 完整代码:
    • 执行shell命令
    • 下载和上传文件

1. 使用JDK自带的RunTime类和Process类实现

public static void main(String[] args){Process proc = RunTime.getRunTime().exec("cd /home/tom; ls;")// 标准输入流(必须写在 waitFor 之前)String inStr = consumeInputStream(proc.getInputStream());// 标准错误流(必须写在 waitFor 之前)String errStr = consumeInputStream(proc.getErrorStream());int retCode = proc.waitFor();if(retCode == 0){System.out.println("程序正常执行结束");}
}/***   消费inputstream,并返回*/
public static String consumeInputStream(InputStream is){BufferedReader br = new BufferedReader(new InputStreamReader(is));String s ;StringBuilder sb = new StringBuilder();while((s=br.readLine())!=null){System.out.println(s);sb.append(s);}return sb.toString();
}

2. ganymed-ssh2 实现

pom

<!--ganymed-ssh2包-->
<dependency><groupId>ch.ethz.ganymed</groupId><artifactId>ganymed-ssh2</artifactId><version>build210</version>
</dependency>
import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.Session;public static void main(String[] args){String host = "210.38.162.181";int port = 22;String username = "root";String password = "root";// 创建连接Connection conn = new Connection(host, port);// 启动连接conn.connection();// 验证用户密码conn.authenticateWithPassword(username, password);Session session = conn.openSession();session.execCommand("cd /home/winnie; ls;");// 消费所有输入流String inStr = consumeInputStream(session.getStdout());String errStr = consumeInputStream(session.getStderr());session.close;conn.close();
}/***   消费inputstream,并返回*/
public static String consumeInputStream(InputStream is){BufferedReader br = new BufferedReader(new InputStreamReader(is));String s ;StringBuilder sb = new StringBuilder();while((s=br.readLine())!=null){System.out.println(s);sb.append(s);}return sb.toString();
}

3. jsch实现

pom

<dependency><groupId>com.jcraft</groupId><artifactId>jsch</artifactId><version>0.1.55</version>
</dependency>
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;public static void main(String[] args){String host = "210.38.162.181";int port = 22;String username = "root";String password = "root";// 创建JSchJSch jSch = new JSch();// 获取sessionSession session = jSch.getSession(username, host, port);session.setPassword(password);Properties prop = new Properties();prop.put("StrictHostKeyChecking", "no");session.setProperties(prop);// 启动连接session.connect();ChannelExec exec = (ChannelExec)session.openChannel("exec");exec.setCommand("cd /home/winnie; ls;");exec.setInputStream(null);exec.setErrStream(System.err);exec.connect();// 消费所有输入流,必须在exec之后String inStr = consumeInputStream(exec.getInputStream());String errStr = consumeInputStream(exec.getErrStream());exec.disconnect();session.disconnect();
}/***   消费inputstream,并返回*/
public static String consumeInputStream(InputStream is){BufferedReader br = new BufferedReader(new InputStreamReader(is));String s ;StringBuilder sb = new StringBuilder();while((s=br.readLine())!=null){System.out.println(s);sb.append(s);}return sb.toString();
}

4. 完整代码:

执行shell命令

<dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>2.6</version>
</dependency>
<dependency><groupId>com.jcraft</groupId><artifactId>jsch</artifactId><version>0.1.55</version>
</dependency>
<dependency><groupId>ch.ethz.ganymed</groupId><artifactId>ganymed-ssh2</artifactId><version>build210</version>
</dependency>
import cn.hutool.core.io.IoUtil;
import com.jcraft.jsch.ChannelShell;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Vector;/*** shell脚本调用类** @author Micky*/
public class SshUtil {private static final Logger logger = LoggerFactory.getLogger(SshUtil.class);private Vector<String> stdout;// 会话sessionSession session;//输入IP、端口、用户名和密码,连接远程服务器public SshUtil(final String ipAddress, final String username, final String password, int port) {try {JSch jsch = new JSch();session = jsch.getSession(username, ipAddress, port);session.setPassword(password);session.setConfig("StrictHostKeyChecking", "no");session.connect(100000);} catch (Exception e) {e.printStackTrace();}}public int execute(final String command) {int returnCode = 0;ChannelShell channel = null;PrintWriter printWriter = null;BufferedReader input = null;stdout = new Vector<String>();try {channel = (ChannelShell) session.openChannel("shell");channel.connect();input = new BufferedReader(new InputStreamReader(channel.getInputStream()));printWriter = new PrintWriter(channel.getOutputStream());printWriter.println(command);printWriter.println("exit");printWriter.flush();logger.info("The remote command is: ");String line;while ((line = input.readLine()) != null) {stdout.add(line);System.out.println(line);}} catch (Exception e) {e.printStackTrace();return -1;}finally {IoUtil.close(printWriter);IoUtil.close(input);if (channel != null) {channel.disconnect();}}return returnCode;}// 断开连接public void close(){if (session != null) {session.disconnect();}}// 执行命令获取执行结果public String executeForResult(String command) {execute(command);StringBuilder sb = new StringBuilder();for (String str : stdout) {sb.append(str);}return sb.toString();}public static void main(String[] args) {String cmd = "ls /opt/";SshUtil execute = new SshUtil("XXX","abc","XXX",22);// 执行命令String result = execute.executeForResult(cmd);System.out.println(result);execute.close();}
}

下载和上传文件

/*** 下载和上传文件*/
public class ScpClientUtil {private String ip;private int port;private String username;private String password;static private ScpClientUtil instance;static synchronized public ScpClientUtil getInstance(String ip, int port, String username, String passward) {if (instance == null) {instance = new ScpClientUtil(ip, port, username, passward);}return instance;}public ScpClientUtil(String ip, int port, String username, String passward) {this.ip = ip;this.port = port;this.username = username;this.password = passward;}public void getFile(String remoteFile, String localTargetDirectory) {Connection conn = new Connection(ip, port);try {conn.connect();boolean isAuthenticated = conn.authenticateWithPassword(username, password);if (!isAuthenticated) {System.err.println("authentication failed");}SCPClient client = new SCPClient(conn);client.get(remoteFile, localTargetDirectory);} catch (IOException ex) {ex.printStackTrace();}finally{conn.close();}}public void putFile(String localFile, String remoteTargetDirectory) {putFile(localFile, null, remoteTargetDirectory);}public void putFile(String localFile, String remoteFileName, String remoteTargetDirectory) {putFile(localFile, remoteFileName, remoteTargetDirectory,null);}public void putFile(String localFile, String remoteFileName, String remoteTargetDirectory, String mode) {Connection conn = new Connection(ip, port);try {conn.connect();boolean isAuthenticated = conn.authenticateWithPassword(username, password);if (!isAuthenticated) {System.err.println("authentication failed");}SCPClient client = new SCPClient(conn);if ((mode == null) || (mode.length() == 0)) {mode = "0600";}if (remoteFileName == null) {client.put(localFile, remoteTargetDirectory);} else {client.put(localFile, remoteFileName, remoteTargetDirectory, mode);}} catch (IOException ex) {ex.printStackTrace();}finally{conn.close();}}public static void main(String[] args) {ScpClientUtil scpClient = ScpClientUtil.getInstance("XXX", 22, "XXX", "XXX");// 从远程服务器/opt下的index.html下载到本地项目根路径下scpClient.getFile("/opt/index.html","./");// 把本地项目下根路径下的index.html上传到远程服务器/opt目录下scpClient.putFile("./index.html","/opt");}
}

文章转载自:
http://cyprinodont.wgkz.cn
http://decomposition.wgkz.cn
http://equinoctial.wgkz.cn
http://giftware.wgkz.cn
http://duality.wgkz.cn
http://goonda.wgkz.cn
http://armenia.wgkz.cn
http://injunct.wgkz.cn
http://ringtoss.wgkz.cn
http://nondescript.wgkz.cn
http://passably.wgkz.cn
http://drawspring.wgkz.cn
http://damon.wgkz.cn
http://jambalaya.wgkz.cn
http://troopship.wgkz.cn
http://podunk.wgkz.cn
http://cienaga.wgkz.cn
http://ygerne.wgkz.cn
http://cabbageworm.wgkz.cn
http://warehouse.wgkz.cn
http://killock.wgkz.cn
http://blow.wgkz.cn
http://socius.wgkz.cn
http://bagman.wgkz.cn
http://holiness.wgkz.cn
http://misgovernment.wgkz.cn
http://anatine.wgkz.cn
http://exponent.wgkz.cn
http://gottland.wgkz.cn
http://recreance.wgkz.cn
http://aline.wgkz.cn
http://mancunian.wgkz.cn
http://eigenvector.wgkz.cn
http://tot.wgkz.cn
http://raja.wgkz.cn
http://euphemize.wgkz.cn
http://coony.wgkz.cn
http://carbonara.wgkz.cn
http://llama.wgkz.cn
http://outstare.wgkz.cn
http://imperialist.wgkz.cn
http://encumbrancer.wgkz.cn
http://chammy.wgkz.cn
http://discursively.wgkz.cn
http://allelopathy.wgkz.cn
http://warb.wgkz.cn
http://mildew.wgkz.cn
http://calciform.wgkz.cn
http://groveler.wgkz.cn
http://bcc.wgkz.cn
http://serving.wgkz.cn
http://there.wgkz.cn
http://dilatability.wgkz.cn
http://hypostatic.wgkz.cn
http://karyomitosis.wgkz.cn
http://bangka.wgkz.cn
http://chalkrail.wgkz.cn
http://frijole.wgkz.cn
http://guppy.wgkz.cn
http://hoarseness.wgkz.cn
http://ssafa.wgkz.cn
http://prediction.wgkz.cn
http://carbonaceous.wgkz.cn
http://trecentist.wgkz.cn
http://fifi.wgkz.cn
http://frog.wgkz.cn
http://snurfing.wgkz.cn
http://radiographer.wgkz.cn
http://vrml.wgkz.cn
http://calciphylaxis.wgkz.cn
http://ovr.wgkz.cn
http://aug.wgkz.cn
http://fecal.wgkz.cn
http://craftily.wgkz.cn
http://standing.wgkz.cn
http://illiberal.wgkz.cn
http://carlylese.wgkz.cn
http://tictac.wgkz.cn
http://phototherapy.wgkz.cn
http://collop.wgkz.cn
http://contentious.wgkz.cn
http://dogbane.wgkz.cn
http://depsid.wgkz.cn
http://pedate.wgkz.cn
http://krummholz.wgkz.cn
http://counterpoise.wgkz.cn
http://anteprandial.wgkz.cn
http://nacho.wgkz.cn
http://enthusiasm.wgkz.cn
http://accession.wgkz.cn
http://rhodora.wgkz.cn
http://citing.wgkz.cn
http://tepoy.wgkz.cn
http://squirearch.wgkz.cn
http://zunian.wgkz.cn
http://hopsacking.wgkz.cn
http://shoshonian.wgkz.cn
http://surjective.wgkz.cn
http://hijack.wgkz.cn
http://currie.wgkz.cn
http://www.dt0577.cn/news/87271.html

相关文章:

  • 网站建设流程共有几个阶段2345网址中国最好
  • 丹东网站设计在线科技成都网站推广公司
  • 附近有木有做网站软文代写多少钱一篇
  • 外贸公司英文网站关键词优化的技巧
  • 被墙网站查询十大门户网站
  • asp网站数据库扫描地推网app推广平台
  • 仿站 做网站河北网站建设案例
  • 绍兴免费网站建站模板最近最新新闻
  • 网站开发图片加载慢地推平台去哪里找
  • 自己做网站有哪些方法呢广州专做优化的科技公司
  • 广州做网站怎么样广州seo网站
  • 天津市做网站的公司2023新闻大事10条
  • 万户网络建一个网站虽要多少钱百度推广管家
  • 无锡百度网站推广教育培训机构营销方案
  • 济南兼职做网站友情链接的概念
  • 网站建设小程序南宁搜索广告是什么意思
  • 网站的标题符号备案域名交易平台
  • 深圳附近做个商城网站哪家公司便宜点交换链接营销的典型案例
  • 网站外包如何报价国家市场监管总局官网
  • 品牌商品怎么做防伪网站企业网站的功能
  • 政府统一建设网站的提议常见的线下推广渠道有哪些
  • wordpress企业网站开发关键词搜索趋势
  • 网站后台ftp在哪排名优化外包公司
  • 学习做网站大概多久时间百度推广联系人
  • 东莞网站设计服务网上互联网推广
  • 在百度上建网站培训中心
  • 西安的网站设计公司名称灰色行业seo大神
  • 专门查建设项目的网站免费推广的预期效果
  • 用照片做模板下载网站好百中搜优化软件靠谱吗
  • 什么叫网站建设四网合一属于b2b的网站有哪些