1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-01 06:05:24 +02:00

Increase ssh default timeout, support ssh proxy options and add tracing support

This commit is contained in:
Martin Oberhuber 2006-05-19 16:04:28 +00:00
parent a91b65d455
commit 57a32aa51a
4 changed files with 95 additions and 21 deletions

View file

@ -0,0 +1 @@
org.eclipse.rse.connectorservice.ssh/debug = true

View file

@ -0,0 +1 @@
org.eclipse.rse.services.ssh/debug = true

View file

@ -11,6 +11,11 @@
package org.eclipse.rse.services.ssh; 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.eclipse.core.runtime.Plugin;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
@ -56,4 +61,36 @@ public class Activator extends Plugin {
public static Activator getDefault() { public static Activator getDefault() {
return plugin; 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);
}
}
} }

View file

@ -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.AbstractFileService;
import org.eclipse.rse.services.files.IFileService; import org.eclipse.rse.services.files.IFileService;
import org.eclipse.rse.services.files.IHostFile; 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.ISshService;
import org.eclipse.rse.services.ssh.ISshSessionProvider; import org.eclipse.rse.services.ssh.ISshSessionProvider;
@ -61,15 +62,30 @@ public class SftpFileService extends AbstractFileService implements IFileService
} }
public void connect() throws Exception { public void connect() throws Exception {
Session session = fSessionProvider.getSession(); Activator.trace("SftpFileService.connecting..."); //$NON-NLS-1$
Channel channel=session.openChannel("sftp"); //$NON-NLS-1$ try {
channel.connect(); Session session = fSessionProvider.getSession();
fChannelSftp=(ChannelSftp)channel; Channel channel=session.openChannel("sftp"); //$NON-NLS-1$
fUserHome = fChannelSftp.pwd(); 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() { public void disconnect() {
fChannelSftp.disconnect(); getChannel("SftpFileService.disconnect").disconnect(); //$NON-NLS-1$
fChannelSftp = null; fChannelSftp = null;
} }
@ -81,8 +97,11 @@ public class SftpFileService extends AbstractFileService implements IFileService
SftpHostFile node = null; SftpHostFile node = null;
SftpATTRS attrs = null; SftpATTRS attrs = null;
try { try {
attrs = fChannelSftp.stat(remoteParent+'/'+fileName); attrs = getChannel("SftpFileService.getFile").stat(remoteParent+'/'+fileName); //$NON-NLS-1$
} catch(Exception e) {} Activator.trace("SftpFileService.getFile done");
} catch(Exception e) {
Activator.trace("SftpFileService.getFile failed: "+e.toString());
}
if (attrs!=null) { if (attrs!=null) {
node = makeHostFile(remoteParent, fileName, attrs); node = makeHostFile(remoteParent, fileName, attrs);
} else { } else {
@ -93,7 +112,7 @@ public class SftpFileService extends AbstractFileService implements IFileService
} }
public boolean isConnected() { 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) 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); NamePatternMatcher filematcher = new NamePatternMatcher(fileFilter, true, true);
List results = new ArrayList(); List results = new ArrayList();
try { 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<vv.size(); ii++) { for(int ii=0; ii<vv.size(); ii++) {
Object obj=vv.elementAt(ii); Object obj=vv.elementAt(ii);
if(obj instanceof ChannelSftp.LsEntry){ if(obj instanceof ChannelSftp.LsEntry){
@ -128,6 +147,7 @@ public class SftpFileService extends AbstractFileService implements IFileService
//of a symbolic link that turns out to point to a file rather than //of a symbolic link that turns out to point to a file rather than
//a directory. In this case, the result is probably expected. //a directory. In this case, the result is probably expected.
//We should try to classify symbolic links as "file" or "dir" correctly. //We should try to classify symbolic links as "file" or "dir" correctly.
Activator.trace("SftpFileService.internalFetch failed: "+e.toString());
e.printStackTrace(); e.printStackTrace();
} }
return (IHostFile[])results.toArray(new IHostFile[results.size()]); return (IHostFile[])results.toArray(new IHostFile[results.size()]);
@ -143,7 +163,7 @@ public class SftpFileService extends AbstractFileService implements IFileService
// try { // try {
// //Note: readlink() is supported only with jsch-0.1.29 or higher. // //Note: readlink() is supported only with jsch-0.1.29 or higher.
// //By catching the exception we remain backward compatible. // //By catching the exception we remain backward compatible.
// String linkTarget=fChannelSftp.readlink(node.getAbsolutePath()); // String linkTarget=getChannel("makeHostFile.readlink").readlink(node.getAbsolutePath()); //$NON-NLS-1$
// node.setLinkTarget(linkTarget); // node.setLinkTarget(linkTarget);
// //TODO: Classify the type of resource linked to as file, folder or broken link // //TODO: Classify the type of resource linked to as file, folder or broken link
// } catch(Exception e) {} // } catch(Exception e) {}
@ -168,12 +188,14 @@ public class SftpFileService extends AbstractFileService implements IFileService
} }
dst += remoteFile; dst += remoteFile;
} }
fChannelSftp.put(localFile.getAbsolutePath(), dst, sftpMonitor, mode); getChannel("SftpFileService.upload").put(localFile.getAbsolutePath(), dst, sftpMonitor, mode); //$NON-NLS-1$
Activator.trace("SftpFileService.upload ok"); //$NON-NLS-1$
} }
catch (Exception e) { catch (Exception e) {
//TODO See download //TODO See download
//e.printStackTrace(); //e.printStackTrace();
//throw new RemoteFileIOException(e); //throw new RemoteFileIOException(e);
Activator.trace("SftpFileService.upload failed: "+e.toString());
return false; return false;
} }
return true; return true;
@ -243,7 +265,8 @@ public class SftpFileService extends AbstractFileService implements IFileService
String remotePath = remoteParent+'/'+remoteFile; String remotePath = remoteParent+'/'+remoteFile;
int mode=ChannelSftp.OVERWRITE; int mode=ChannelSftp.OVERWRITE;
MyProgressMonitor sftpMonitor = new MyProgressMonitor(monitor); MyProgressMonitor sftpMonitor = new MyProgressMonitor(monitor);
fChannelSftp.get(remotePath, localFile.getAbsolutePath(), sftpMonitor, mode); getChannel("SftpFileService.download").get(remotePath, localFile.getAbsolutePath(), sftpMonitor, mode); //$NON-NLS-1$
Activator.trace("SftpFileService.download ok"); //$NON-NLS-1$
} }
catch (Exception e) { catch (Exception e) {
//TODO handle exception properly: happens e.g. when trying to download a symlink. //TODO handle exception properly: happens e.g. when trying to download a symlink.
@ -251,6 +274,7 @@ public class SftpFileService extends AbstractFileService implements IFileService
//<=3 (e.g. "4: Failure"). therefore it is better for now to just return false. //<=3 (e.g. "4: Failure"). therefore it is better for now to just return false.
//e.printStackTrace(); //e.printStackTrace();
//throw new RemoteFileIOException(e); //throw new RemoteFileIOException(e);
Activator.trace("SftpFileService.download failed: "+e.toString()); //$NON-NLS-1$
return false; return false;
} }
return true; return true;
@ -281,11 +305,13 @@ public class SftpFileService extends AbstractFileService implements IFileService
IHostFile result = null; IHostFile result = null;
try { try {
String fullPath = remoteParent + '/' + fileName; String fullPath = remoteParent + '/' + fileName;
OutputStream os = fChannelSftp.put(fullPath); OutputStream os = getChannel("SftpFileService.createFile").put(fullPath); //$NON-NLS-1$
os.close(); os.close();
SftpATTRS attrs = fChannelSftp.stat(fullPath); SftpATTRS attrs = getChannel("SftpFileService.createFile.stat").stat(fullPath); //$NON-NLS-1$
result = makeHostFile(remoteParent, fileName, attrs); result = makeHostFile(remoteParent, fileName, attrs);
Activator.trace("SftpFileService.createFile ok"); //$NON-NLS-1$
} catch (Exception e) { } catch (Exception e) {
Activator.trace("SftpFileService.createFile failed: "+e.toString()); //$NON-NLS-1$
e.printStackTrace(); e.printStackTrace();
// DKM commenting out because services don't know about this class // DKM commenting out because services don't know about this class
// throw new RemoteFileIOException(e); // throw new RemoteFileIOException(e);
@ -298,10 +324,12 @@ public class SftpFileService extends AbstractFileService implements IFileService
IHostFile result = null; IHostFile result = null;
try { try {
String fullPath = remoteParent + '/' + folderName; String fullPath = remoteParent + '/' + folderName;
fChannelSftp.mkdir(fullPath); getChannel("SftpFileService.createFolder").mkdir(fullPath); //$NON-NLS-1$
SftpATTRS attrs = fChannelSftp.stat(fullPath); SftpATTRS attrs = getChannel("SftpFileService.createFolder.stat").stat(fullPath); //$NON-NLS-1$
result = makeHostFile(remoteParent, folderName, attrs); result = makeHostFile(remoteParent, folderName, attrs);
Activator.trace("SftpFileService.createFolder ok"); //$NON-NLS-1$
} catch (Exception e) { } catch (Exception e) {
Activator.trace("SftpFileService.createFolder failed: "+e.toString()); //$NON-NLS-1$
e.printStackTrace(); e.printStackTrace();
// DKM commenting out because services don't know about this class // DKM commenting out because services don't know about this class
//throw new RemoteFileIOException(e); //throw new RemoteFileIOException(e);
@ -314,16 +342,18 @@ public class SftpFileService extends AbstractFileService implements IFileService
boolean ok=false; boolean ok=false;
try { try {
String fullPath = remoteParent + '/' + fileName; String fullPath = remoteParent + '/' + fileName;
SftpATTRS attrs = fChannelSftp.stat(fullPath); SftpATTRS attrs = getChannel("SftpFileService.delete").stat(fullPath); //$NON-NLS-1$
if (attrs==null) { if (attrs==null) {
//doesn't exist, nothing to do //doesn't exist, nothing to do
} else if (attrs.isDir()) { } else if (attrs.isDir()) {
fChannelSftp.rmdir(fullPath); getChannel("SftpFileService.delete.rmdir").rmdir(fullPath); //$NON-NLS-1$
} else { } else {
fChannelSftp.rm(fullPath); getChannel("SftpFileService.delete.rm").rm(fullPath); //$NON-NLS-1$
} }
ok=true; ok=true;
Activator.trace("SftpFileService.delete ok"); //$NON-NLS-1$
} catch (Exception e) { } catch (Exception e) {
Activator.trace("SftpFileService.delete: "+e.toString()); //$NON-NLS-1$
e.printStackTrace(); e.printStackTrace();
// DKM commenting out because services don't know about this class // DKM commenting out because services don't know about this class
//throw new RemoteFileIOException(e); //throw new RemoteFileIOException(e);
@ -337,9 +367,11 @@ public class SftpFileService extends AbstractFileService implements IFileService
try { try {
String fullPathOld = remoteParent + '/' + oldName; String fullPathOld = remoteParent + '/' + oldName;
String fullPathNew = remoteParent + '/' + newName; String fullPathNew = remoteParent + '/' + newName;
fChannelSftp.rename(fullPathOld, fullPathNew); getChannel("SftpFileService.rename").rename(fullPathOld, fullPathNew); //$NON-NLS-1$
ok=true; ok=true;
Activator.trace("SftpFileService.rename ok"); //$NON-NLS-1$
} catch (Exception e) { } catch (Exception e) {
Activator.trace("SftpFileService.rename failed: "+e.toString()); //$NON-NLS-1$
e.printStackTrace(); e.printStackTrace();
// DKM commenting out because services don't know about this class // DKM commenting out because services don't know about this class
//throw new RemoteFileIOException(e); //throw new RemoteFileIOException(e);
@ -363,6 +395,7 @@ public class SftpFileService extends AbstractFileService implements IFileService
public int runCommand(IProgressMonitor monitor, String command) throws SystemMessageException public int runCommand(IProgressMonitor monitor, String command) throws SystemMessageException
{ {
Activator.trace("SftpFileService.runCommand "+command); //$NON-NLS-1$ //$NON-NLS-2$
int result = -1; int result = -1;
if (monitor!=null) { if (monitor!=null) {
monitor.beginTask(command, 20); monitor.beginTask(command, 20);
@ -391,10 +424,12 @@ public class SftpFileService extends AbstractFileService implements IFileService
try{Thread.sleep(1000);}catch(Exception ee){} try{Thread.sleep(1000);}catch(Exception ee){}
} }
result = channel.getExitStatus(); result = channel.getExitStatus();
Activator.trace("SftpFileService.runCommand ok, result: "+result); //$NON-NLS-1$ //$NON-NLS-2$
} catch(Exception e) { } catch(Exception e) {
// DKM // DKM
// not visible to this plugin // not visible to this plugin
// throw new RemoteFileIOException(e); // throw new RemoteFileIOException(e);
Activator.trace("SftpFileService.runCommand failed: "+e.toString()); //$NON-NLS-1$ //$NON-NLS-2$
} finally { } finally {
if (monitor!=null) { if (monitor!=null) {
monitor.done(); monitor.done();