### Eclipse Workspace Patch 1.0 #P org.eclipse.rse.services.files.ftp Index: src/org/eclipse/rse/internal/services/files/ftp/FTPService.java =================================================================== RCS file: /cvsroot/dsdp/org.eclipse.tm.rse/plugins/org.eclipse.rse.services.files.ftp/src/org/eclipse/rse/internal/services/files/ftp/FTPService.java,v retrieving revision 1.33 diff -u -r1.33 FTPService.java --- src/org/eclipse/rse/internal/services/files/ftp/FTPService.java 2 Aug 2007 15:23:58 -0000 1.33 +++ src/org/eclipse/rse/internal/services/files/ftp/FTPService.java 9 Aug 2007 17:28:07 -0000 @@ -69,6 +69,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.SocketException; import java.text.MessageFormat; import java.util.ArrayList; import java.util.HashMap; @@ -164,6 +165,7 @@ public void close() throws IOException { super.close(); client.completePendingCommand(); + client.logout(); } } @@ -199,6 +201,7 @@ public void close() throws IOException { super.close(); client.completePendingCommand(); + client.logout(); } } @@ -411,6 +414,48 @@ return _ftpClient; } + + private FTPClient cloneFTPClient(boolean isBinary) + { + + FTPClient ftpClient = new FTPClient(); + try { + ftpClient.connect(_ftpClient.getRemoteAddress()); + ftpClient.login(_userId,_password); + + if (_clientConfigProxy != null) { + ftpClient.configure(_clientConfigProxy.getFTPClientConfig()); + } else { + // UNIX parsing by default if no suitable parser found + ftpClient.configure(new FTPClientConfig(FTPClientConfig.SYST_UNIX)); + } + + if (_isPassiveDataConnectionMode) { + ftpClient.enterLocalPassiveMode(); + } + + if (isBinary) { + ftpClient.setFileType(FTP.BINARY_FILE_TYPE); + } else { + ftpClient.setFileType(FTP.ASCII_FILE_TYPE); + } + + ftpClient.registerSpyStream(_ftpLoggingOutputStream); + + } catch (Exception e) {} + + + return ftpClient; + } + + private void disconnect(FTPClient ftpClient) + { + ftpClient.registerSpyStream(null); + try { + ftpClient.logout(); + } catch (IOException e) {} + } + /* * (non-Javadoc) * @see org.eclipse.rse.services.files.IFileService#getFile(String, String, IProgressMonitor) @@ -1305,29 +1350,15 @@ InputStream stream = null; - if(_commandMutex.waitForLock(monitor, Long.MAX_VALUE)) - { - try { - FTPClient ftpClient = getFTPClient(); - ftpClient.changeWorkingDirectory(remoteParent); - setFileType(isBinary); - stream = new FTPBufferedInputStream(ftpClient.retrieveFileStream(remoteFile), ftpClient); + try { + FTPClient ftpClient = cloneFTPClient(isBinary); + ftpClient.changeWorkingDirectory(remoteParent); + stream = new FTPBufferedInputStream(ftpClient.retrieveFileStream(remoteFile), ftpClient); } catch (Exception e) { throw new RemoteFileIOException(e); - }finally { - //TODO I am not 100% sure but I _think_ that the _commandMutex - //may only be released once reading the stream is complete, - //since in FTPBufferedInputStream.close() a pending command - //is being sent. - //After all, the safer solution would be to have a separate - //FTP client connection to the remote for the download, such - //that dir channel remains free. See bug #198636 - _commandMutex.release(); } - } else { - throw new RemoteFileCancelledException(); - } + return stream; } @@ -1343,20 +1374,14 @@ OutputStream stream = null; - if(_commandMutex.waitForLock(monitor, Long.MAX_VALUE)) - { - try { - FTPClient ftpClient = getFTPClient(); - clearCache(remoteParent); - ftpClient.changeWorkingDirectory(remoteParent); - setFileType(isBinary); - stream = new FTPBufferedOutputStream(ftpClient.storeFileStream(remoteFile), ftpClient); - } - catch (Exception e) { - throw new RemoteFileIOException(e); - }finally { - _commandMutex.release(); - } + try { + FTPClient ftpClient = cloneFTPClient(isBinary); + clearCache(remoteParent); + ftpClient.changeWorkingDirectory(remoteParent); + stream = new FTPBufferedOutputStream(ftpClient.storeFileStream(remoteFile), ftpClient); + } + catch (Exception e) { + throw new RemoteFileIOException(e); } return stream;