diff --git a/rse/plugins/org.eclipse.rse.connectorservice.ssh/.options b/rse/plugins/org.eclipse.rse.connectorservice.ssh/.options new file mode 100644 index 00000000000..e846377b804 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.connectorservice.ssh/.options @@ -0,0 +1 @@ +org.eclipse.rse.connectorservice.ssh/debug = true diff --git a/rse/plugins/org.eclipse.rse.services.ssh/.options b/rse/plugins/org.eclipse.rse.services.ssh/.options new file mode 100644 index 00000000000..536700caea9 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.services.ssh/.options @@ -0,0 +1 @@ +org.eclipse.rse.services.ssh/debug = true diff --git a/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/services/ssh/Activator.java b/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/services/ssh/Activator.java index a0983d23813..f83c8b244a7 100644 --- a/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/services/ssh/Activator.java +++ b/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/services/ssh/Activator.java @@ -11,6 +11,11 @@ package org.eclipse.rse.services.ssh; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; + +import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Plugin; import org.osgi.framework.BundleContext; @@ -56,4 +61,36 @@ public class Activator extends Plugin { public static Activator getDefault() { return plugin; } + + private static Boolean fTracingOn = null; + public static boolean isTracingOn() { + if (fTracingOn==null) { + String id = plugin.getBundle().getSymbolicName(); + String val = Platform.getDebugOption(id + "/debug"); //$NON-NLS-1$ + if ("true".equals(val)) { + fTracingOn = Boolean.TRUE; + } else { + fTracingOn = Boolean.FALSE; + } + } + return fTracingOn.booleanValue(); + } + public static String getTimestamp() { + try { + DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); //$NON-NLS-1$ + return formatter.format(new Date()); + } catch (Exception e) { + // If there were problems writing out the date, ignore and + // continue since that shouldn't stop us from logging the rest + // of the information + } + return Long.toString(System.currentTimeMillis()); + } + public static void trace(String msg) { + if (isTracingOn()) { + String fullMsg = getTimestamp() + " | " + Thread.currentThread().getName() + " | " + msg; + System.out.println(fullMsg); + } + } + } diff --git a/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/services/ssh/files/SftpFileService.java b/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/services/ssh/files/SftpFileService.java index 73dadf46665..c772cc31ff1 100644 --- a/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/services/ssh/files/SftpFileService.java +++ b/rse/plugins/org.eclipse.rse.services.ssh/src/org/eclipse/rse/services/ssh/files/SftpFileService.java @@ -27,6 +27,7 @@ import org.eclipse.rse.services.clientserver.messages.SystemMessageException; import org.eclipse.rse.services.files.AbstractFileService; import org.eclipse.rse.services.files.IFileService; import org.eclipse.rse.services.files.IHostFile; +import org.eclipse.rse.services.ssh.Activator; import org.eclipse.rse.services.ssh.ISshService; import org.eclipse.rse.services.ssh.ISshSessionProvider; @@ -61,15 +62,30 @@ public class SftpFileService extends AbstractFileService implements IFileService } public void connect() throws Exception { - Session session = fSessionProvider.getSession(); - Channel channel=session.openChannel("sftp"); //$NON-NLS-1$ - channel.connect(); - fChannelSftp=(ChannelSftp)channel; - fUserHome = fChannelSftp.pwd(); + Activator.trace("SftpFileService.connecting..."); //$NON-NLS-1$ + try { + Session session = fSessionProvider.getSession(); + Channel channel=session.openChannel("sftp"); //$NON-NLS-1$ + channel.connect(); + fChannelSftp=(ChannelSftp)channel; + fUserHome = fChannelSftp.pwd(); + Activator.trace("SftpFileService.connected"); //$NON-NLS-1$ + } catch(Exception e) { + Activator.trace("SftpFileService.connecting failed: "+e.toString()); + throw e; + } + } + + protected ChannelSftp getChannel(String task) { + Activator.trace(task); + if (fChannelSftp==null || !fChannelSftp.isConnected()) { + Activator.trace(task + ": channel not connected: "+fChannelSftp); + } + return fChannelSftp; } public void disconnect() { - fChannelSftp.disconnect(); + getChannel("SftpFileService.disconnect").disconnect(); //$NON-NLS-1$ fChannelSftp = null; } @@ -81,8 +97,11 @@ public class SftpFileService extends AbstractFileService implements IFileService SftpHostFile node = null; SftpATTRS attrs = null; try { - attrs = fChannelSftp.stat(remoteParent+'/'+fileName); - } catch(Exception e) {} + attrs = getChannel("SftpFileService.getFile").stat(remoteParent+'/'+fileName); //$NON-NLS-1$ + Activator.trace("SftpFileService.getFile done"); + } catch(Exception e) { + Activator.trace("SftpFileService.getFile failed: "+e.toString()); + } if (attrs!=null) { node = makeHostFile(remoteParent, fileName, attrs); } else { @@ -93,7 +112,7 @@ public class SftpFileService extends AbstractFileService implements IFileService } public boolean isConnected() { - return fChannelSftp.isConnected(); + return getChannel("SftpFileService.isConnected()").isConnected(); //$NON-NLS-1$ } protected IHostFile[] internalFetch(IProgressMonitor monitor, String parentPath, String fileFilter, int fileType) @@ -104,7 +123,7 @@ public class SftpFileService extends AbstractFileService implements IFileService NamePatternMatcher filematcher = new NamePatternMatcher(fileFilter, true, true); List results = new ArrayList(); try { - java.util.Vector vv=fChannelSftp.ls(parentPath); + java.util.Vector vv=getChannel("SftpFileService.internalFetch").ls(parentPath); //$NON-NLS-1$ for(int ii=0; ii