当前位置: 首页>>代码示例>>Java>>正文


Java Channel.isConnected方法代码示例

本文整理汇总了Java中com.jcraft.jsch.Channel.isConnected方法的典型用法代码示例。如果您正苦于以下问题:Java Channel.isConnected方法的具体用法?Java Channel.isConnected怎么用?Java Channel.isConnected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.jcraft.jsch.Channel的用法示例。


在下文中一共展示了Channel.isConnected方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: rename

import com.jcraft.jsch.Channel; //导入方法依赖的package包/类
@Override
public boolean rename(String newName){
    Channel channel = null;
    try {
         channel = SFTPSession.getInstance().getSFTPChannel(mUri);
        ((ChannelSftp)channel).rename(mUri.getPath(), new File(new File(mUri.getPath()).getParentFile(), newName).getAbsolutePath());
        channel.disconnect();
        return true;
    } catch (Exception e) {
        e.printStackTrace();
    }finally {
        if(channel!=null&&channel.isConnected())
            channel.disconnect();
    }
    return false;
}
 
开发者ID:archos-sa,项目名称:aos-FileCoreLibrary,代码行数:17,代码来源:SftpFileEditor.java

示例2: move

import com.jcraft.jsch.Channel; //导入方法依赖的package包/类
@Override
public boolean move(Uri uri) {
    if(!mUri.getScheme().equals(uri.getScheme())|| !mUri.getHost().equals(uri.getHost())||mUri.getPort()!=uri.getPort())
        return false;
    Channel channel = null;
    try {
        channel = SFTPSession.getInstance().getSFTPChannel(mUri);
        ((ChannelSftp)channel).rename(mUri.getPath(),uri.getPath());
        channel.disconnect();
        return true;
    } catch (Exception e) {
        e.printStackTrace();
    }finally {
        if(channel!=null&&channel.isConnected())
            channel.disconnect();
    }
    return false;
}
 
开发者ID:archos-sa,项目名称:aos-FileCoreLibrary,代码行数:19,代码来源:SftpFileEditor.java

示例3: exists

import com.jcraft.jsch.Channel; //导入方法依赖的package包/类
@Override
public boolean exists() {
    Channel channel = null;
    try {
        channel = SFTPSession.getInstance().getSFTPChannel(mUri);
        SftpATTRS attrs =  ((ChannelSftp)channel).stat(mUri.getPath());
        channel.disconnect();
        return attrs !=null;
    } catch (Exception e) {
        if(channel!=null&&channel.isConnected())
            channel.disconnect();
        e.printStackTrace();
    }finally {
        if(channel!=null&&channel.isConnected())
            channel.disconnect();
    }
    return false;
}
 
开发者ID:archos-sa,项目名称:aos-FileCoreLibrary,代码行数:19,代码来源:SftpFileEditor.java

示例4: getChannelShell

import com.jcraft.jsch.Channel; //导入方法依赖的package包/类
/**
 * Get a {@link ChannelShell}
 *
 * @param channelSessionKey the session key that identifies the channel
 * @return {@link ChannelShell}
 * @throws Exception thrown by borrowObject and invalidateObject
 */
private ChannelShell getChannelShell(final ChannelSessionKey channelSessionKey) throws Exception {
    final long startTime = System.currentTimeMillis();
    Channel channel;
    do {
        LOGGER.debug("borrowing a channel...");
        channel = channelPool.borrowObject(channelSessionKey);
        if (channel != null) {
            LOGGER.debug("channel {} borrowed", channel.getId());
            if (!channel.isConnected()) {
                try {
                    LOGGER.debug("channel {} connecting...", channel.getId());
                    channel.connect(CHANNEL_CONNECT_TIMEOUT);
                    LOGGER.debug("channel {} connected!", channel.getId());
                } catch (final JSchException jsche) {
                    LOGGER.error("Borrowed channel {} connection failed! Invalidating the channel...",
                            channel.getId(), jsche);
                    channelPool.invalidateObject(channelSessionKey, channel);
                }
            } else {
                LOGGER.debug("Channel {} already connected!", channel.getId());
            }
        }

        if ((channel == null || !channel.isConnected()) && (System.currentTimeMillis() - startTime) > CHANNEL_BORROW_LOOP_WAIT_TIME) {
            final String errMsg = MessageFormat.format("Failed to get a channel within {0} ms! Aborting channel acquisition!",
                    CHANNEL_BORROW_LOOP_WAIT_TIME);
            LOGGER.error(errMsg);
            throw new JschServiceException(errMsg);
        }
    } while (channel == null || !channel.isConnected());
    return (ChannelShell) channel;
}
 
开发者ID:cerner,项目名称:jwala,代码行数:40,代码来源:JschServiceImpl.java

示例5: executeCommandNoResponse

import com.jcraft.jsch.Channel; //导入方法依赖的package包/类
public static void executeCommandNoResponse( Session sessionObj, String command )
    throws JSchException, IOException
{
    logger.debug( "Starting to execute command [" + maskedPasswordString( command ) + "]" );

    if ( sessionObj != null && command != null && !"".equals( command ) )
    {
        Channel channel = null;

        try
        {
            channel = sessionObj.openChannel( "exec" );
            ( (ChannelExec) channel ).setCommand( command );
            channel.setInputStream( null );
            ( (ChannelExec) channel ).setErrStream( System.err );
            channel.getInputStream();
            channel.connect();
            /* We do not care about whether the command succeeds or not */

            if ( channel.isClosed() && channel.getExitStatus() != 0 )
            {
                logger.debug( "Command exited with error code " + channel.getExitStatus() );
            }
        }
        catch ( Exception e )
        {
            logger.error( "Received exception during command execution", e );
        }
        finally
        {
            if ( channel != null && channel.isConnected() )
            {
                channel.disconnect();
            }
            logger.debug( "End of execution of command [" + maskedPasswordString( command ) + "]" );
        }
    }
}
 
开发者ID:vmware,项目名称:OHMS,代码行数:39,代码来源:SshUtil.java

示例6: executeCommandNoResponse

import com.jcraft.jsch.Channel; //导入方法依赖的package包/类
public static void executeCommandNoResponse( Session sessionObj, String command )
    throws JSchException, IOException
{
    logger.debug( "Starting to execute command [" + command + "]" );

    if ( sessionObj != null && command != null && !"".equals( command ) )
    {
        Channel channel = null;

        try
        {
            channel = sessionObj.openChannel( "exec" );
            ( (ChannelExec) channel ).setCommand( command );
            channel.setInputStream( null );
            ( (ChannelExec) channel ).setErrStream( System.err );
            channel.getInputStream();
            channel.connect();
            /* We do not care about whether the command succeeds or not */

            if ( channel.isClosed() && channel.getExitStatus() != 0 )
            {
                logger.debug( "Command exited with error code " + channel.getExitStatus() );
            }
        }
        catch ( Exception e )
        {
            logger.error( "Received exception during command execution", e );
        }
        finally
        {
            if ( channel != null && channel.isConnected() )
            {
                channel.disconnect();
            }
            logger.debug( "End of execution of command [" + command + "]" );
        }
    }
}
 
开发者ID:vmware,项目名称:OHMS,代码行数:39,代码来源:EsxiSshUtil.java

示例7: executeCommand

import com.jcraft.jsch.Channel; //导入方法依赖的package包/类
/**
 * It executes the command and returns the response back to the calling function. This function will expect Session
 * object and command string as parameters .
 *
 * @param sessionObj
 * @param command
 * @return
 * @throws JSchException
 * @throws IOException
 */
public static String executeCommand( Session sessionObj, String command )
    throws JSchException, IOException
{
    StringBuilder builder = null;
    logger.debug( "Starting to execute command [" + maskedPasswordString( command ) + "]" );

    if ( sessionObj != null && command != null && !"".equals( command ) )
    {
        builder = new StringBuilder();
        Channel channel = null;

        int arrMaxSize = 1024;

        try
        {
            channel = sessionObj.openChannel( "exec" );
            ( (ChannelExec) channel ).setCommand( command );
            channel.setInputStream( null );
            ( (ChannelExec) channel ).setErrStream( System.err );
            InputStream in = channel.getInputStream();
            channel.connect();

            byte[] tmp = new byte[arrMaxSize];

            while ( true )
            {
                while ( in.available() > 0 )
                {
                    int i = in.read( tmp, 0, arrMaxSize );
                    if ( i < 0 )
                        break;
                    builder.append( new String( tmp, 0, i ) );
                }

                if ( channel.isClosed() )
                {
                    break;
                }
                try
                {
                    Thread.sleep( 500 );
                }
                catch ( Exception ee )
                {

                }
            }

            if ( channel.isClosed() && channel.getExitStatus() != 0 )
            {
                logger.debug( "Command exited with error code " + channel.getExitStatus() );
            }
        }
        catch ( Exception e )
        {
            logger.error( "Received exception during command execution", e );
        }
        finally
        {
            if ( channel != null && channel.isConnected() )
            {
                channel.disconnect();
            }
            logger.debug( "End of execution of command [" + maskedPasswordString( command ) + "]" );
        }
        return builder.toString();
    }
    return null;
}
 
开发者ID:vmware,项目名称:OHMS,代码行数:80,代码来源:SshUtil.java

示例8: executeCommand

import com.jcraft.jsch.Channel; //导入方法依赖的package包/类
/**
 * It executes the command and returns the response back to the calling function. This function will expect Session
 * object and command string as parameters .
 * 
 * @param sessionObj
 * @param command
 * @return
 * @throws JSchException
 * @throws IOException
 */
public static String executeCommand( Session sessionObj, String command )
    throws JSchException, IOException
{
    StringBuilder builder = null;
    logger.debug( "Starting to execute command [" + command + "]" );

    if ( sessionObj != null && command != null && !"".equals( command ) )
    {
        builder = new StringBuilder();
        Channel channel = null;

        int arrMaxSize = 1024;

        try
        {
            channel = sessionObj.openChannel( "exec" );
            ( (ChannelExec) channel ).setCommand( command );
            channel.setInputStream( null );
            ( (ChannelExec) channel ).setErrStream( System.err );
            InputStream in = channel.getInputStream();
            channel.connect();

            byte[] tmp = new byte[arrMaxSize];

            while ( true )
            {
                while ( in.available() > 0 )
                {
                    int i = in.read( tmp, 0, arrMaxSize );
                    if ( i < 0 )
                        break;
                    builder.append( new String( tmp, 0, i ) );
                }

                if ( channel.isClosed() )
                {
                    break;
                }
                try
                {
                    Thread.sleep( 500 );
                }
                catch ( Exception ee )
                {

                }
            }

            if ( channel.isClosed() && channel.getExitStatus() != 0 )
            {
                logger.debug( "Command exited with error code " + channel.getExitStatus() );
            }
        }
        catch ( Exception e )
        {
            logger.error( "Received exception during command execution", e );
        }
        finally
        {
            if ( channel != null && channel.isConnected() )
            {
                channel.disconnect();
            }
            logger.debug( "End of execution of command [" + command + "]" );
        }
        return builder.toString();
    }
    return null;
}
 
开发者ID:vmware,项目名称:OHMS,代码行数:80,代码来源:SshUtil.java

示例9: executeCommand

import com.jcraft.jsch.Channel; //导入方法依赖的package包/类
/**
 * It executes the command and returns the response back to the calling function. This function will expect Session
 * object and command string as parameters .
 *
 * @param sessionObj
 * @param command
 * @return
 * @throws JSchException
 * @throws IOException
 */
public static String executeCommand( Session sessionObj, String command )
    throws JSchException, IOException
{
    StringBuilder builder = null;
    logger.debug( "Starting to execute command [" + command + "]" );

    if ( sessionObj != null && command != null && !"".equals( command ) )
    {
        builder = new StringBuilder();
        Channel channel = null;

        int arrMaxSize = 1024;

        try
        {
            channel = sessionObj.openChannel( "exec" );
            ( (ChannelExec) channel ).setCommand( command );
            channel.setInputStream( null );
            ( (ChannelExec) channel ).setErrStream( System.err );
            InputStream in = channel.getInputStream();
            channel.connect();

            byte[] tmp = new byte[arrMaxSize];

            while ( true )
            {
                while ( in.available() > 0 )
                {
                    int i = in.read( tmp, 0, arrMaxSize );
                    if ( i < 0 )
                        break;
                    builder.append( new String( tmp, 0, i ) );
                }

                if ( channel.isClosed() )
                {
                    break;
                }
                try
                {
                    Thread.sleep( 500 );
                }
                catch ( Exception ee )
                {

                }
            }

            if ( channel.isClosed() && channel.getExitStatus() != 0 )
            {
                logger.debug( "Command exited with error code " + channel.getExitStatus() );
            }
        }
        catch ( Exception e )
        {
            logger.error( "Received exception during command execution", e );
        }
        finally
        {
            if ( channel != null && channel.isConnected() )
            {
                channel.disconnect();
            }
            logger.debug( "End of execution of command [" + command + "]" );
        }
        return builder.toString();
    }
    return null;
}
 
开发者ID:vmware,项目名称:OHMS,代码行数:80,代码来源:EsxiSshUtil.java

示例10: createJschChannel

import com.jcraft.jsch.Channel; //导入方法依赖的package包/类
private Connection createJschChannel(Session session, InputStream jsch_in,
		OutputStream out) throws JSchException, IOException {
	final InputStream in;
	Channel channel;
	// open shell channel with vt100 term
	channel = session.openChannel("shell");
	((ChannelShell) channel).setPtyType("vt100");
	((ChannelShell) channel).setPty(true);
	channel.setInputStream(jsch_in);
	in = channel.getInputStream();

	channel.connect(10000);

	// sleep 500s in case we don't have open channel permission and server
	// close the channel.
	try {
		Thread.sleep(500);
	} catch (InterruptedException e) {
	}
	if (!channel.isConnected()) {
		throw new NemoException(
				"channel has been closed by peer. maybe you don't have permission");
	}

	final Session _session = session;
	final InputStream _in = this.createVT100Filter(in);
	final OutputStream _out = out;
	return new Connection() {
		boolean _active = true;

		@Override
		public void close() {
			_active = false;
			_session.disconnect();
		}

		@Override
		public OutputStream getOutputStream() {
			return _out;
		}

		@Override
		public InputStream getInputStream() {
			return _in;
		}

		@Override
		public boolean isActive() {
			return _active && _session.isConnected();
		}

	};

}
 
开发者ID:kira8565,项目名称:JavaExpect,代码行数:55,代码来源:SshDriver.java

示例11: sendFile

import com.jcraft.jsch.Channel; //导入方法依赖的package包/类
private void sendFile(Channel channel, String localFile, String remoteName, String mode)
        throws IOException, RemoteScpException {
    byte[] buffer = new byte[BUFFER_SIZE];

    OutputStream os = new BufferedOutputStream(channel.getOutputStream(),
            SEND_FILE_BUFFER_LENGTH);
    InputStream is = new BufferedInputStream(channel.getInputStream(), SEND_BYTES_BUFFER_LENGTH);

    try {
        if (channel.isConnected()) {
            channel.start();
        } else {
            channel.connect();
        }
    } catch (JSchException jsche) {
        throw new IOException("Channel connection problems", jsche);
    }

    readResponse(is);

    File f = new File(localFile);
    long remain = f.length();

    String cMode = mode;
    if (cMode == null) {
        cMode = "0600";
    }
    String cline = "C" + cMode + " " + remain + " " + remoteName + "\n";

    os.write(cline.getBytes());
    os.flush();

    readResponse(is);

    try (FileInputStream fis = new FileInputStream(f)) {
        while (remain > 0) {
            int trans;
            if (remain > buffer.length) {
                trans = buffer.length;
            } else {
                trans = (int) remain;
            }
            if (fis.read(buffer, 0, trans) != trans) {
                throw new IOException("Cannot read enough from local file " + localFile);
            }

            os.write(buffer, 0, trans);

            remain -= trans;
        }

        fis.close();
    }

    os.write(0);
    os.flush();

    readResponse(is);

    os.write("E\n".getBytes());
    os.flush();
}
 
开发者ID:apache,项目名称:ant-ivy,代码行数:63,代码来源:Scp.java


注:本文中的com.jcraft.jsch.Channel.isConnected方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。