diff --git a/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/internal/connectorservice/ssh/SshConnectorService.java b/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/internal/connectorservice/ssh/SshConnectorService.java index b05dedaf79d..0df6d81713b 100644 --- a/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/internal/connectorservice/ssh/SshConnectorService.java +++ b/rse/plugins/org.eclipse.rse.connectorservice.ssh/src/org/eclipse/rse/internal/connectorservice/ssh/SshConnectorService.java @@ -13,6 +13,7 @@ * Martin Oberhuber (Wind River) - [186773] split ISystemRegistryUI from ISystemRegistry * Martin Oberhuber (Wind River) - [186761] make the port setting configurable * Martin Oberhuber (Wind River) - [198790] make SSH createSession() protected + * Martin Oberhuber (Wind River) - [203500] Support encodings for SSH Sftp paths *******************************************************************************/ package org.eclipse.rse.internal.connectorservice.ssh; @@ -61,6 +62,8 @@ public class SshConnectorService extends StandardConnectorService implements ISs private static final int CONNECT_DEFAULT_TIMEOUT = 60; //seconds private Session session; private SessionLostHandler fSessionLostHandler; + /** Indicates the default string encoding on this platform */ + private static String _defaultEncoding = new java.io.InputStreamReader(new java.io.ByteArrayInputStream(new byte[0])).getEncoding(); public SshConnectorService(IHost host) { super(SshConnectorResources.SshConnectorService_Name, SshConnectorResources.SshConnectorService_Description, host, SSH_DEFAULT_PORT); @@ -209,6 +212,15 @@ public class SshConnectorService extends StandardConnectorService implements ISs public Session getSession() { return session; } + + public String getControlEncoding() { + //TODO this code should be in IHost + String encoding = getHost().getDefaultEncoding(false); + if (encoding==null) encoding = getHost().getDefaultEncoding(true); + if (encoding==null) encoding = _defaultEncoding; + // + return encoding; + } /** * Handle session-lost events. diff --git a/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/internal/services/files/ftp/FTPService.java b/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/internal/services/files/ftp/FTPService.java index 7c7fc77e3e9..43baad826d4 100644 --- a/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/internal/services/files/ftp/FTPService.java +++ b/rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/internal/services/files/ftp/FTPService.java @@ -37,7 +37,7 @@ * Javier Montalvo Orus (Symbian) - Fixing 168120 - [ftp] root filter resolves to home dir * Javier Montalvo Orus (Symbian) - Fixing 169680 - [ftp] FTP files subsystem and service should use passive mode * Javier Montalvo Orus (Symbian) - Fixing 174828 - [ftp] Folders are attempted to be removed as files - * Javier Montalvo Orus (Symbian) - Fixing 176216 - [api] FTP sould provide API to allow clients register their own FTPListingParser + * Javier Montalvo Orus (Symbian) - Fixing 176216 - [api] FTP should provide API to allow clients register their own FTPListingParser * Martin Oberhuber (Wind River) - [186128] Move IProgressMonitor last in all API * Javier Montalvo Orus (Symbian) - improved autodetection of FTPListingParser * Javier Montalvo Orus (Symbian) - [187096] Drag&Drop + Copy&Paste shows error message on FTP connection @@ -61,6 +61,7 @@ * Martin Oberhuber (Wind River) - [203306] Fix Deadlock comparing two files on FTP * Martin Oberhuber (Wind River) - [204669] Fix ftp path concatenation on systems using backslash separator * Martin Oberhuber (Wind River) - [203490] Fix NPE in FTPService.getUserHome() + * Martin Oberhuber (Wind River) - [203500] Support encodings for FTP paths ********************************************************************************/ package org.eclipse.rse.internal.services.files.ftp; @@ -74,6 +75,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.io.UnsupportedEncodingException; import java.text.MessageFormat; import java.util.ArrayList; import java.util.HashMap; @@ -96,6 +98,8 @@ import org.eclipse.rse.services.clientserver.FileTypeMatcher; import org.eclipse.rse.services.clientserver.IMatcher; import org.eclipse.rse.services.clientserver.NamePatternMatcher; import org.eclipse.rse.services.clientserver.PathUtility; +import org.eclipse.rse.services.clientserver.messages.IndicatorException; +import org.eclipse.rse.services.clientserver.messages.SystemMessage; import org.eclipse.rse.services.clientserver.messages.SystemMessageException; import org.eclipse.rse.services.files.AbstractFileService; import org.eclipse.rse.services.files.IFileService; @@ -117,6 +121,7 @@ public class FTPService extends AbstractFileService implements IFileService, IFT private transient String _userId; private transient String _password; private transient int _portNumber; + private transient String _controlEncoding; //Encoding to be used for file and path names private OutputStream _ftpLoggingOutputStream; private IPropertySet _ftpPropertySet; @@ -273,13 +278,69 @@ public class FTPService extends AbstractFileService implements IFileService, IFT { _entryParserFactory = entryParserFactory; } + + /** + * Set the character encoding to be used on the FTP command channel. + * The encoding must be compatible with ASCII since FTP commands will + * be sent with the same encoding. Therefore, wide + * (16-bit) encodings are not supported. + * @param encoding Encoding to set + */ + public void setControlEncoding(String encoding) + { + _controlEncoding = encoding; + } + /** + * Check whether the given Unicode String can be properly represented with the + * specified control encoding. Throw a SystemMessageException if it turns out + * that information would be lost. + * @param s String to check + * @return the original String or a quoted or re-coded version if possible + * @throws SystemMessageException if information is lost + */ + protected String checkEncoding(String s) throws SystemMessageException { + String encoding = _controlEncoding!=null ? _controlEncoding : getFTPClient().getControlEncoding(); + try { + byte[] bytes = s.getBytes(encoding); + String decoded = new String(bytes, encoding); + if (!s.equals(decoded)) { + int i=0; + int lmax = Math.min(s.length(), decoded.length()); + while( (i + _ftpService.setControlEncoding(encoding); _ftpService.connect(); - - } /* (non-Javadoc) @@ -163,4 +173,4 @@ public class FTPConnectorService extends StandardConnectorService return (_ftpService != null && _ftpService.isConnected()); } -} \ No newline at end of file +}