本文整理汇总了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();
}
开发者ID:apache,项目名称:karaf-eik,代码行数:38,代码来源:KarafSshShellConnection.java
示例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);
}
开发者ID:qoswork,项目名称:opennmszh,代码行数:26,代码来源:SSHTerminalTest.java
示例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);
}
开发者ID:qoswork,项目名称:opennmszh,代码行数:23,代码来源:SSHWindowTest.java
示例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();
}
}
开发者ID:apache,项目名称:tomee,代码行数:36,代码来源:SSHServerTest.java
示例5: doStart
import org.apache.sshd.SshClient; //导入依赖的package包/类
@Override
protected void doStart() throws Exception {
client = SshClient.setUpDefaultClient();
client.start();
super.doStart();
}
开发者ID:HydAu,项目名称:Camel,代码行数:8,代码来源:SshProducer.java
示例6: setup
import org.apache.sshd.SshClient; //导入依赖的package包/类
@PostConstruct
protected void setup(){
sshClient = SshClient.setUpDefaultClient();
sshClient.start();
}
开发者ID:northlander,项目名称:activemft,代码行数:6,代码来源:SftpReceiver.java
示例7: setSshClient
import org.apache.sshd.SshClient; //导入依赖的package包/类
public void setSshClient(final SshClient sshClient) {
this.sshClient = sshClient;
}
开发者ID:apache,项目名称:karaf-eik,代码行数:4,代码来源:KarafSshShellConnection.java
示例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);
}
}
}
开发者ID:cloudnautique,项目名称:cloud-cattle,代码行数:54,代码来源:SshAgentConnectionFactory.java
示例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);
}
}
}
开发者ID:ibuildthecloud,项目名称:dstack,代码行数:54,代码来源:SshAgentConnectionFactory.java
示例10: getSshClient
import org.apache.sshd.SshClient; //导入依赖的package包/类
public SshClient getSshClient() {
return client;
}
开发者ID:northshorefiend,项目名称:sshproxyj,代码行数:4,代码来源:ProxyCommandFactory.java
示例11: setSshClient
import org.apache.sshd.SshClient; //导入依赖的package包/类
public void setSshClient(SshClient client) {
this.client = client;
}
开发者ID:northshorefiend,项目名称:sshproxyj,代码行数:4,代码来源:ProxyCommandFactory.java
示例12: SshConnectionFactory
import org.apache.sshd.SshClient; //导入依赖的package包/类
public SshConnectionFactory() {
client = SshClient.setUpDefaultClient();
}
开发者ID:northshorefiend,项目名称:sshproxyj,代码行数:4,代码来源:SshConnectionFactory.java
注:本文中的org.apache.sshd.SshClient类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论