diff --git a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchConnection.java b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchConnection.java index 4e83f70adec..325f20c104b 100644 --- a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchConnection.java +++ b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/JSchConnection.java @@ -171,7 +171,6 @@ public class JSchConnection implements IRemoteConnection { public static final String EMPTY_STRING = ""; //$NON-NLS-1$ private String fWorkingDir; - private boolean fIsOpen; private final IJSchService fJSchService; @@ -263,7 +262,6 @@ public class JSchConnection implements IRemoteConnection { } } fSessions.clear(); - fIsOpen = false; fireConnectionChangeEvent(IRemoteConnectionChangeEvent.CONNECTION_CLOSED); } @@ -661,7 +659,7 @@ public class JSchConnection implements IRemoteConnection { */ @Override public boolean isOpen() { - boolean isOpen = fIsOpen & fSessions.size() > 0; + boolean isOpen = fSessions.size() > 0; if (isOpen) { for (Session session : fSessions) { isOpen &= session.isConnected(); @@ -814,23 +812,18 @@ public class JSchConnection implements IRemoteConnection { public void open(IProgressMonitor monitor) throws RemoteConnectionException { if (!isOpen()) { checkIsConfigured(); - SubMonitor subMon = SubMonitor.convert(monitor, 70); + SubMonitor subMon = SubMonitor.convert(monitor, 60); Session session = newSession(fManager.getUserAuthenticator(this), subMon.newChild(10)); if (subMon.isCanceled()) { throw new RemoteConnectionException(Messages.JSchConnection_Connection_was_cancelled); } + //getCwd checks the exec channel before checkConfiguration checks the sftp channel + fWorkingDir = getCwd(subMon.newChild(10)); if (!checkConfiguration(session, subMon.newChild(20))) { newSession(fManager.getUserAuthenticator(this), subMon.newChild(10)); loadEnv(subMon.newChild(10)); } - fIsOpen = true; - try { - fWorkingDir = getCwd(subMon.newChild(10)); - loadProperties(subMon.newChild(10)); - } catch (RemoteConnectionException e) { - fIsOpen = false; - throw e; - } + loadProperties(subMon.newChild(10)); fireConnectionChangeEvent(IRemoteConnectionChangeEvent.CONNECTION_OPENED); } } diff --git a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/commands/AbstractRemoteCommand.java b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/commands/AbstractRemoteCommand.java index 95ec7aa0fcb..60ea373d49b 100755 --- a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/commands/AbstractRemoteCommand.java +++ b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/commands/AbstractRemoteCommand.java @@ -126,7 +126,7 @@ public abstract class AbstractRemoteCommand { * @see java.util.concurrent.Callable#call() */ @Override - public abstract T1 call() throws JSchException, IOException; + public abstract T1 call() throws JSchException, IOException, RemoteConnectionException; private void finalizeCmdInThread() { setChannel(null); diff --git a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/commands/ExecCommand.java b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/commands/ExecCommand.java index 0dffebc5217..8e8fb3b2573 100644 --- a/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/commands/ExecCommand.java +++ b/bundles/org.eclipse.remote.jsch.core/src/org/eclipse/remote/internal/jsch/core/commands/ExecCommand.java @@ -29,10 +29,12 @@ public class ExecCommand extends AbstractRemoteCommand { final SubMonitor subMon = SubMonitor.convert(monitor, 10); ExecCallable c = new ExecCallable() { @Override - public String call() throws JSchException { + public String call() throws JSchException, RemoteConnectionException { getChannel().setCommand(fCommand); ByteArrayOutputStream stream = new ByteArrayOutputStream(); + ByteArrayOutputStream err = new ByteArrayOutputStream(); getChannel().setOutputStream(stream); + getChannel().setErrStream(err); getChannel().connect(); while (!getChannel().isClosed() && !getProgressMonitor().isCanceled()) { synchronized (this) { @@ -46,6 +48,9 @@ public class ExecCommand extends AbstractRemoteCommand { if (getProgressMonitor().isCanceled()) { return ""; //$NON-NLS-1$ } + if (getChannel().getExitStatus()!=0) { + throw new RemoteConnectionException(err.toString()); + } return stream.toString(); } };