use of com.jn.agileway.ssh.client.SshException in project agileway by fangjinuo.
the class Ssh2ForwardingClient method startLocalForwarding.
@Override
public ForwardingChannelInfo startLocalForwarding(String bindToHost, int bindToPort, String destHost, int destPort) throws SshException {
ForwardingChannelInfo channel = new ForwardingChannelInfo(ForwardingChannelInfo.LOCAL_FORWARDING_CHANNEL, bindToHost, bindToPort, destHost, destPort);
if (!localForwarderMap.containsKey(ForwardingChannelInfo.id(channel))) {
Connection delegate = this.connection.getDelegate();
try {
LocalPortForwarder localPortForwarder = delegate.createLocalPortForwarder(new InetSocketAddress(bindToHost, bindToPort), destHost, destPort);
localForwarderMap.put(ForwardingChannelInfo.id(channel), localPortForwarder);
} catch (Throwable ex) {
throw new SshException(ex);
}
}
return channel;
}
use of com.jn.agileway.ssh.client.SshException in project agileway by fangjinuo.
the class SshCommandLineLauncher method exec.
@Override
public SshCommandExecutionAdaptor exec(CommandLine commandLine, Map<String, String> environmentVariables, File workingDirectory) throws IOException {
try {
if (!connection.isConnected()) {
throw new SshException(new IllegalStateException("connection is not connected"));
}
final SessionedChannel sessionChannel = connection.openSession();
Preconditions.checkNotNull(sessionChannel, "the ssh exec session channel is null");
String command = commandLine.getCommandLineString();
if (workingDirectory != null) {
String path = workingDirectory.getPath();
path = path.replace("\\", "/");
command = "cd " + path + ";" + command;
}
if (Emptys.isNotEmpty(environmentVariables)) {
String envs = null;
if (environmentSettingsSupplier != null) {
envs = environmentSettingsSupplier.get(environmentVariables);
}
if (Strings.isNotEmpty(envs)) {
command = envs + command;
} else {
Collects.forEach(environmentVariables, new Consumer2<String, String>() {
@Override
public void accept(String variable, String value) {
sessionChannel.env(variable, value);
}
});
}
}
sessionChannel.exec(command);
return new SshCommandExecutionAdaptor(sessionChannel);
} catch (Throwable ex) {
throw Throwables.wrapAsRuntimeException(ex);
}
}
use of com.jn.agileway.ssh.client.SshException in project agileway by fangjinuo.
the class SshjSessionedChannel method signal.
@Override
public void signal(Signal signal) throws SshException {
Preconditions.checkNotEmpty(signal, "the signal is null or empty");
Preconditions.checkArgument(signal != Signal.UNKNOWN, "the signal is UNKNOWN");
net.schmizz.sshj.connection.channel.direct.Signal sg = null;
String name = signal.name();
sg = net.schmizz.sshj.connection.channel.direct.Signal.fromString(name);
try {
if (this.shell != null) {
this.shell.signal(sg);
}
if (this.command != null) {
this.command.signal(sg);
}
} catch (Throwable ex) {
throw new SshException(ex);
}
}
use of com.jn.agileway.ssh.client.SshException in project agileway by fangjinuo.
the class SshjSessionedChannel method internalShell.
@Override
protected void internalShell() throws SshException {
try {
this.shell = this.session.startShell();
initStreams();
} catch (Throwable ex) {
throw new SshException(ex);
}
}
use of com.jn.agileway.ssh.client.SshException in project agileway by fangjinuo.
the class SshjSessionedChannel method internalExec.
@Override
protected void internalExec(String command) throws SshException {
Preconditions.checkNotEmpty(command, "the command is illegal : {}", command);
try {
this.command = this.session.exec(command);
initStreams();
} catch (Throwable ex) {
throw new SshException(ex);
}
}
Aggregations