本文整理汇总了Java中org.apache.sshd.SshClient类的典型用法代码示例。如果您正苦于以下问题:Java SshClient类的具体用法?Java SshClient怎么用?Java SshClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SshClient类属于org.apache.sshd包,在下文中一共展示了SshClient类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: KarafSshShellConnection
import org.apache.sshd.SshClient; //导入依赖的package包/类
/**
* Creates a remote shell connection to a Karaf instance using the SSH
* protocol
*
* @param connectionUrl
* the coordinates used to establish the connection
* @param credentials
* the username and password used to authenticate when connection
* @param inputStream
* the {@link InputStream} used to interact with the remote
* system
* @param outputStream
* the {@link OutputStream} used to receive data from
* {@code stdout} of the remote system
* @param errorStream
* the {@link OutputStream} used to receive data from
* {@code stderr} of the remote system
*/
public KarafSshShellConnection(
final KarafSshConnectionUrl connectionUrl,
final Credentials credentials,
final InputStream inputStream,
final OutputStream outputStream,
final OutputStream errorStream)
{
this.connectionUrl = connectionUrl;
this.credentials = credentials;
this.inputStream = inputStream;
this.outputStream = outputStream;
this.errorStream = errorStream;
this.exception = null;
this.sshClient = SshClient.setUpDefaultClient();
}
示例2: setUp
import org.apache.sshd.SshClient; //导入依赖的package包/类
@SuppressWarnings("serial")
@Before
public void setUp() throws Exception {
app = new Application() {
@Override
public void init() {}
};
mainWindow = new Window();
app.setMainWindow(mainWindow);
SSHWindow sshWindow = new SSHWindow(null, 200, 200);
app.getMainWindow().addWindow(sshWindow);
SshClient client = SshClient.setUpDefaultClient();
client.start();
ClientSession session = null;
try {
session = client.connect(testHost, testPort).await().getSession();
} catch (Exception e) {
fail("Could not connect to host");
}
sshTerm = new SSHTerminal(sshWindow, session, 200, 200);
sshWindow.addComponent(sshTerm);
}
示例3: setup
import org.apache.sshd.SshClient; //导入依赖的package包/类
@SuppressWarnings("serial")
@Before
public void setup () {
app = new Application() {
@Override
public void init() {}
};
sshWindow = new SSHWindow(null, 200, 200);
client = SshClient.setUpDefaultClient();
client.start();
try {
session = client.connect(testHost, testPort).await().getSession();
} catch (Exception e) {
fail("Could not connect to host");
}
sshWindow2 = new SSHWindow(session, 200, 200);
mainWindow = new Window();
app.setMainWindow(mainWindow);
app.getMainWindow().addWindow(sshWindow);
app.getMainWindow().addWindow(sshWindow2);
}
示例4: call
import org.apache.sshd.SshClient; //导入依赖的package包/类
@Test(timeout = 10000L)
public void call() throws Exception {
final SshClient client = SshClient.setUpDefaultClient();
client.start();
try {
final ClientSession session = client.connect("localhost", 4222).await().getSession();
session.authPassword("jonathan", "secret");
final ClientChannel channel = session.createChannel("shell");
ByteArrayOutputStream sent = new ByteArrayOutputStream();
PipedOutputStream pipedIn = new TeePipedOutputStream(sent);
channel.setIn(new PipedInputStream(pipedIn));
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayOutputStream err = new ByteArrayOutputStream();
channel.setOut(out);
channel.setErr(err);
channel.open();
pipedIn.write("properties\r\n".getBytes());
pipedIn.flush();
pipedIn.write("exit\r\n".getBytes());
pipedIn.flush();
channel.waitFor(ClientChannel.CLOSED, 0);
channel.close(false);
client.stop();
assertTrue(new String(sent.toByteArray()).contains("properties\r\nexit\r\n"));
assertTrue(new String(out.toByteArray()).contains("ServerService(id=ssh)"));
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
示例5: doStart
import org.apache.sshd.SshClient; //导入依赖的package包/类
@Override
protected void doStart() throws Exception {
client = SshClient.setUpDefaultClient();
client.start();
super.doStart();
}
示例6: setup
import org.apache.sshd.SshClient; //导入依赖的package包/类
@PostConstruct
protected void setup(){
sshClient = SshClient.setUpDefaultClient();
sshClient.start();
}
示例7: setSshClient
import org.apache.sshd.SshClient; //导入依赖的package包/类
public void setSshClient(final SshClient sshClient) {
this.sshClient = sshClient;
}
示例8: createConnection
import org.apache.sshd.SshClient; //导入依赖的package包/类
protected AgentConnection createConnection(Agent agent, SshConnectionOptions opts) throws IOException, InterruptedException {
SshClient client = getClient();
ClientSession session = null;
boolean success = false;
try {
session = connect(client, opts);
String hostIp = getIp(opts);
String script = copyBootStrap(session);
int port = setForwarding(session);
log.info("Allocated random port [{}] on [{}]", port, opts.getHost());
EofAwareChannelExec exec = callBootStrap(agent, session, String.format("%s --read-env --port %d --ip %s", script, port, hostIp));
final SshAgentConnection sshAgent = new SshAgentConnection(agent.getId(), agent.getUri(), eventService, this, session, exec, port);
success = true;
connections.add(sshAgent);
exec.onEof(new Runnable() {
@Override
public void run() {
sshAgent.close();
}
});
CloseListener listener = new CloseListener(sshAgent);
session.addListener(listener);
OpenFuture execOpen = exec.open();
execOpen.addListener(listener);
try {
execOpen.await(SSH_TIMEOUT.get(), TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
throw new IllegalStateException("Interrupted waiting for script [" + script + "]", e);
}
if ( ! execOpen.isOpened() ) {
throw new IOException("Failed to start script [" + script + "]");
}
success = writeAuth(sshAgent);
if ( ! success ) {
sshAgent.close();
throw new IOException("Failed to write context info for agent [" + sshAgent.getAgentId() + "]");
}
return sshAgent;
} finally {
if ( ! success && session != null ) {
session.close(true);
}
}
}
示例9: createConnection
import org.apache.sshd.SshClient; //导入依赖的package包/类
protected AgentConnection createConnection(Agent agent, SshConnectionOptions opts) throws IOException, InterruptedException {
SshClient client = getClient();
ClientSession session = null;
boolean success = false;
try {
session = connect(client, opts);
String hostIp = getIp(opts);
String script = copyBootStrap(session);
int port = setForwarding(session);
log.info("Allocated random port [{}] on [{}]", port, opts.getHost());
EofAwareChannelExec exec = callBootStrap(agent, session, String.format("%s --port %d --ip %s", script, port, hostIp));
final SshAgentConnection sshAgent = new SshAgentConnection(agent.getId(), agent.getUri(), eventService, this, session, exec, port);
success = true;
connections.add(sshAgent);
exec.onEof(new Runnable() {
@Override
public void run() {
sshAgent.close();
}
});
CloseListener listener = new CloseListener(sshAgent);
session.addListener(listener);
OpenFuture execOpen = exec.open();
execOpen.addListener(listener);
try {
execOpen.await(SSH_TIMEOUT.get(), TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
throw new IllegalStateException("Interrupted waiting for script [" + script + "]", e);
}
if ( ! execOpen.isOpened() ) {
throw new IOException("Failed to start script [" + script + "]");
}
success = writeAuth(sshAgent);
if ( ! success ) {
sshAgent.close();
throw new IOException("Failed to write context info for agent [" + sshAgent.getAgentId() + "]");
}
return sshAgent;
} finally {
if ( ! success && session != null ) {
session.close(true);
}
}
}
示例10: getSshClient
import org.apache.sshd.SshClient; //导入依赖的package包/类
public SshClient getSshClient() {
return client;
}
示例11: setSshClient
import org.apache.sshd.SshClient; //导入依赖的package包/类
public void setSshClient(SshClient client) {
this.client = client;
}
示例12: SshConnectionFactory
import org.apache.sshd.SshClient; //导入依赖的package包/类
public SshConnectionFactory() {
client = SshClient.setUpDefaultClient();
}