
net.sf.sshapi.impl.jsch.JschStreamChannel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sshapi-jsch Show documentation
Show all versions of sshapi-jsch Show documentation
JSch is a pure Java implementation of SSH2. JSch allows you to connect to an sshd server and use port forwarding, X11 forwarding, file transfer, etc., and you can integrate its functionality into your own Java programs. JSch is licensed under BSD style license.
Downloads and more information about JSch may be found at http://www.jcraft.com/jsch/.
This library is the provider bridge for SSHAPI.
/*
* Copyright (c) 2010 The JavaSSH Project
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package net.sf.sshapi.impl.jsch;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import net.sf.sshapi.AbstractDataProducingComponent;
import net.sf.sshapi.SshConfiguration;
import net.sf.sshapi.SshException;
import net.sf.sshapi.SshExtendedStreamChannel;
import com.jcraft.jsch.Channel;
abstract class JschStreamChannel extends AbstractDataProducingComponent implements SshExtendedStreamChannel {
private final Channel channel;
private final SshConfiguration configuration;
private InputStream in;
private OutputStream out;
private InputStream ext;
public JschStreamChannel(SshConfiguration configuration, Channel channel) throws SshException {
this.channel = channel;
this.configuration = configuration;
}
public int exitCode() throws IOException {
return channel.getExitStatus();
}
public InputStream getInputStream() throws IOException {
return in;
}
public OutputStream getOutputStream() throws IOException {
return out;
}
public InputStream getExtendedInputStream() throws IOException {
return ext;
}
protected Channel getChannel() {
return channel;
}
public void onClose() throws SshException {
channel.disconnect();
}
public void onOpen() throws SshException {
try {
in = channel.getInputStream();
out = channel.getOutputStream();
ext = channel.getExtInputStream();
channel.connect(Integer.parseInt(configuration.getProperties().getProperty(JschSshProvider.CFG_CHANNEL_CONNECT_TIMEOUT,
"3000")));
} catch (Exception e) {
throw new SshException("Failed to connect channel.", e);
}
onChannelOpen();
}
protected SshConfiguration getConfiguration() {
return configuration;
}
protected abstract void onChannelOpen() throws SshException;
protected abstract void onChannelClose() throws SshException;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy