热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

com.jcraft.jsch.Channel.isConnected()方法的使用及代码示例

本文整理了Java中com.jcraft.jsch.Channel.isConnected()方法的一些代码示例,展示了Channel.isConnected()的具体用法。这些代码示例主要来源于Gi

本文整理了Java中com.jcraft.jsch.Channel.isConnected()方法的一些代码示例,展示了Channel.isConnected()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Channel.isConnected()方法的具体详情如下:
包路径:com.jcraft.jsch.Channel
类名称:Channel
方法名:isConnected

Channel.isConnected介绍

[英]returns true if this channel is currently connected (which also means that the session is still connected).
[中]如果此通道当前已连接(这也意味着会话仍处于连接状态),则返回true。

代码示例

代码示例来源:origin: looly/hutool

/**
* 关闭会话通道
*
* @param channel 会话通道
* @since 4.0.3
*/
public static void close(Channel channel) {
if (channel != null && channel.isConnected()) {
channel.disconnect();
}
}

代码示例来源:origin: looly/hutool

/**
* 关闭会话通道
*
* @param channel 会话通道
* @since 4.0.3
*/
public static void close(Channel channel) {
if (channel != null && channel.isConnected()) {
channel.disconnect();
}
}

代码示例来源:origin: dadoonet/fscrawler

private ChannelSftp openSSHConnection(Server server) throws Exception {
logger.debug("Opening SSH connection to {}@{}", server.getUsername(), server.getHostname());
JSch jsch = new JSch();
Session session = jsch.getSession(server.getUsername(), server.getHostname(), server.getPort());
java.util.Properties cOnfig= new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
if (server.getPemPath() != null) {
jsch.addIdentity(server.getPemPath());
}
session.setConfig(config);
if (server.getPassword() != null) {
session.setPassword(server.getPassword());
}
session.connect();
//Open a new session for SFTP.
Channel channel = session.openChannel("sftp");
channel.connect();
//checking SSH client connection.
if (!channel.isConnected()) {
logger.warn("Cannot connect with SSH to {}@{}", server.getUsername(),
server.getHostname());
throw new RuntimeException("Can not connect to " + server.getUsername() + "@" + server.getHostname());
}
logger.debug("SSH connection successful");
return (ChannelSftp) channel;
}
}

代码示例来源:origin: dufyun/learn-tech-collection

@Override
public boolean isConnected() {
boolean flag = false;
if(this.channel != null && this.channel.isConnected()){
flag = true;
}
return flag;
}

代码示例来源:origin: cn.hutool/hutool-all

/**
* 关闭会话通道
*
* @param channel 会话通道
* @since 4.0.3
*/
public static void close(Channel channel) {
if (channel != null && channel.isConnected()) {
channel.disconnect();
}
}

代码示例来源:origin: Impetus/jumbune

public void closeChannel(Channel channel){
if(channel!=null && channel.isConnected()){
channel.disconnect();
}
}

代码示例来源:origin: org.hudsonci.plugins/gerrit-events

/**
* Returns if there already is an open session on this connection.
*
* @return true if it is so.
*/
@Override
public synchronized boolean isSessionOpen() {
return currentSession != null && currentSession.isConnected() && !currentSession.isEOF();
}

代码示例来源:origin: com.sonyericsson.hudson.plugins.gerrit/gerrit-events

/**
* Returns if there already is an open session on this connection.
* @return true if it is so.
*/
public synchronized boolean isSessionOpen() {
return currentSession != null && currentSession.isConnected() && !currentSession.isEOF();
}

代码示例来源:origin: Impetus/jumbune

public void closeChannel(Channel channel){
if(channel!=null && channel.isConnected()){
channel.disconnect();
}
}

代码示例来源:origin: Impetus/jumbune

public void closeChannel(Channel channel){
if(channel!=null && channel.isConnected()){
channel.disconnect();
}
}

代码示例来源:origin: Impetus/jumbune

public void closeChannel(Channel channel){
if(channel!=null && channel.isConnected()){
channel.disconnect();
}
}

代码示例来源:origin: Adobe-Consulting-Services/acs-aem-commons

@Override
public void close() throws IOException {
if (currentStream != null) {
currentStream.close();
}
if (channel != null && channel.isConnected()) {
channel.disconnect();
channel = null;
}
if (session != null) {
session.disconnect();
session = null;
}
}

代码示例来源:origin: bradand/XMouse

public boolean executeShellCommand(String cmd){
MainActivity.recentCmdTextView.setText(cmd);
if(session==null){
return false;
}
if(session.isConnected() && channel.isConnected()){
try {
//Log.d(TAG,cmd+", "+session.isConnected());
cmd=cmd+"\r\n";
pin.write(cmd.getBytes());
pin.flush();
return true;
} catch (IOException e) {
e.printStackTrace();
}
}
return false;
}
public class SshExecTask extends AsyncTask {

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.jsch

void write(Packet packet) throws Exception{
if(reply){
channel.reply=-1;
}
session.write(packet);
if(reply){
long start=System.currentTimeMillis();
long timeout=channel.connectTimeout;
while(channel.isConnected() && channel.reply==-1){
try{Thread.sleep(10);}
catch(Exception ee){
}
if(timeout>0L &&
(System.currentTimeMillis()-start)>timeout){
channel.reply=0;
throw new JSchException("channel request: timeout");
}
}
if(channel.reply==0){
throw new JSchException("failed to send channel request");
}
}
}
}

代码示例来源:origin: org.mule.jsch/jsch

void write(Packet packet) throws Exception{
if(reply){
channel.reply=-1;
}
session.write(packet);
if(reply){
long start=System.currentTimeMillis();
long timeout=channel.connectTimeout;
while(channel.isConnected() && channel.reply==-1){
try{Thread.sleep(10);}
catch(Exception ee){
}
if(timeout>0L &&
(System.currentTimeMillis()-start)>timeout){
channel.reply=0;
throw new JSchException("channel request: timeout");
}
}
if(channel.reply==0){
throw new JSchException("failed to send channel request");
}
}
}
}

代码示例来源:origin: org.ikasan/ikasan-connector-sftp-classes

/**
* Method that tests if the underlying library's session and channels are
* valid and connected.
*
* @return true if fully connected, false
* otherwise
*/
public boolean isConnected()
{
// Getting the status of each connection related object
boolean a = (this.session == null) ? false : this.session.isConnected();
boolean b = (this.channel == null) ? false : this.channel.isConnected();
boolean c = (this.channelSftp == null) ? false : this.channelSftp.isConnected();
// If all the above are true, then we are connected
// Else, two possibilities, either we are all happily disconnected, or
// one of the above is null (when it shouldn't - hence assume
// disconnected
return (a && b && c);
}

代码示例来源:origin: com.jcraft.jsch/com.springsource.com.jcraft.jsch

void write(Packet packet) throws Exception{
if(reply){
channel.reply=-1;
}
session.write(packet);
if(reply){
long start=System.currentTimeMillis();
long timeout=channel.connectTimeout;
while(channel.isConnected() && channel.reply==-1){
try{Thread.sleep(10);}
catch(Exception ee){
}
if(timeout>0L &&
(System.currentTimeMillis()-start)>timeout){
channel.reply=0;
throw new JSchException("channel request: timeout");
}
}
if(channel.reply==0){
throw new JSchException("failed to send channel request");
}
}
}
}

代码示例来源:origin: net.sourceforge.expectj/expectj

/**
* Takes control over an existing SSH channel.
*
* @param channel The channel we should control. If this channel isn't
* already connected, {@link Channel#connect()} will be called.
*
* @throws IOException If connecting the channel fails.
*/
public SshSpawn(Channel channel) throws IOException {
if (!channel.isConnected()) {
try {
channel.connect();
} catch (JSchException e) {
throw new IOException("Failed connecting the channel", e) ;
}
}
this.m_channel = channel;
m_toSocket = m_channel.getInputStream();
m_fromSocket = m_channel.getOutputStream();
}

代码示例来源:origin: com.redhat.rhevm.api/rhevm-api-powershell-expectj

/**
* Takes control over an existing SSH channel.
*
* @param channel The channel we should control. If this channel isn't
* already connected, {@link Channel#connect()} will be called.
*
* @throws IOException If connecting the channel fails.
*/
public SshSpawn(Channel channel) throws IOException {
if (!channel.isConnected()) {
try {
channel.connect();
} catch (JSchException e) {
throw new IOException("Failed connecting the channel", e) ;
}
}
this.m_channel = channel;
m_toSocket = m_channel.getInputStream();
m_fromSocket = m_channel.getOutputStream();
}

代码示例来源:origin: com.axway.ats.expectj/ats-expectj

/**
* Takes control over an existing SSH channel.
*
* @param channel The channel we should control. If this channel isn't
* already connected, {@link Channel#connect()} will be called.
*
* @throws IOException If connecting the channel fails.
*/
public SshSpawn( Channel channel ) throws IOException {
if( !channel.isConnected() ) {
try {
channel.connect();
} catch( JSchException e ) {
throw new IOException( "Failed connecting the channel", e );
}
}
this.m_channel = channel;
m_toSocket = m_channel.getInputStream();
m_fromSocket = m_channel.getOutputStream();
}

推荐阅读
  • 这个问题困扰了我两天,卸载Dr.COM客户端(我们学校上网要装这个客户端登陆服务器,以后只能在网页里输入用户名和密码了),问题解决了。问题的现象:在实验室机台式机上安装openfire和sp ... [详细]
  • 生产环境下JVM调优参数的设置实例
     正文前先来一波福利推荐: 福利一:百万年薪架构师视频,该视频可以学到很多东西,是本人花钱买的VIP课程,学习消化了一年,为了支持一下女朋友公众号也方便大家学习,共享给大家。福利二 ... [详细]
  • 关于我们EMQ是一家全球领先的开源物联网基础设施软件供应商,服务新产业周期的IoT&5G、边缘计算与云计算市场,交付全球领先的开源物联网消息服务器和流处理数据 ... [详细]
  • 自动轮播,反转播放的ViewPagerAdapter的使用方法和效果展示
    本文介绍了如何使用自动轮播、反转播放的ViewPagerAdapter,并展示了其效果。该ViewPagerAdapter支持无限循环、触摸暂停、切换缩放等功能。同时提供了使用GIF.gif的示例和github地址。通过LoopFragmentPagerAdapter类的getActualCount、getActualItem和getActualPagerTitle方法可以实现自定义的循环效果和标题展示。 ... [详细]
  • 本文介绍了如何清除Eclipse中SVN用户的设置。首先需要查看使用的SVN接口,然后根据接口类型找到相应的目录并删除相关文件。最后使用SVN更新或提交来应用更改。 ... [详细]
  • 本文介绍了一个适用于PHP应用快速接入TRX和TRC20数字资产的开发包,该开发包支持使用自有Tron区块链节点的应用场景,也支持基于Tron官方公共API服务的轻量级部署场景。提供的功能包括生成地址、验证地址、查询余额、交易转账、查询最新区块和查询交易信息等。详细信息可参考tron-php的Github地址:https://github.com/Fenguoz/tron-php。 ... [详细]
  • SpringBoot整合SpringSecurity+JWT实现单点登录
    SpringBoot整合SpringSecurity+JWT实现单点登录,Go语言社区,Golang程序员人脉社 ... [详细]
  • Java如何导入和导出Excel文件的方法和步骤详解
    本文详细介绍了在SpringBoot中使用Java导入和导出Excel文件的方法和步骤,包括添加操作Excel的依赖、自定义注解等。文章还提供了示例代码,并将代码上传至GitHub供访问。 ... [详细]
  •     这里使用自己编译的hadoop-2.7.0版本部署在windows上,记得几年前,部署hadoop需要借助于cygwin,还需要开启ssh服务,最近发现,原来不需要借助cy ... [详细]
  • 大坑|左上角_pycharm连接服务器同步写代码(图文详细过程)
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了pycharm连接服务器同步写代码(图文详细过程)相关的知识,希望对你有一定的参考价值。pycharm连接服务 ... [详细]
  • Annotation的大材小用
    为什么80%的码农都做不了架构师?最近在开发一些通用的excel数据导入的功能,由于涉及到导入的模块很多,所以开发了一个比较通用的e ... [详细]
  • 一、Struts2是一个基于MVC设计模式的Web应用框架在MVC设计模式中,Struts2作为控制器(Controller)来建立模型与视图的数据交互。Struts2优点1、实现 ... [详细]
  • 交换机配置:intg100unshintvlani1ipadd192.168.56.177qstelseuser-iv4authaaaproinsshupl3qsshuserpyt ... [详细]
  • Jenkins的分布式构建,在Jenkins的配置中叫做节点,分布式构建能够让同一套代码或项目在不同的环境(如:Windows和Linux系统)中编译、部署等。将jenkins项目 ... [详细]
  • 【教程】SecureCRT8.5安装和注册的详细步骤及操作指南
    00.目录文章目录00.目录01.SecureCRT8.5介绍02.SecureCRT8.5的特性03.SecureCRT8.5的特点04.SecureCRT8.5安装05.Sec ... [详细]
author-avatar
伟经理_469
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有