1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-25 18:05:33 +02:00

Fix exception handling for cloneFTPClient()

This commit is contained in:
Martin Oberhuber 2007-08-10 13:17:27 +00:00
parent 4bdb33cd8e
commit 61b5360d32

View file

@ -424,31 +424,38 @@ public class FTPService extends AbstractFileService implements IFileService, IFT
*/ */
private FTPClient cloneFTPClient(boolean isBinary) throws IOException private FTPClient cloneFTPClient(boolean isBinary) throws IOException
{ {
FTPClient ftpClient = new FTPClient(); FTPClient ftpClient = new FTPClient();
boolean ok=false;
ftpClient.connect(_ftpClient.getRemoteAddress()); try {
ftpClient.login(_userId,_password); ftpClient.connect(_ftpClient.getRemoteAddress());
ftpClient.login(_userId,_password);
if (_clientConfigProxy != null) {
ftpClient.configure(_clientConfigProxy.getFTPClientConfig()); if (_clientConfigProxy != null) {
} else { ftpClient.configure(_clientConfigProxy.getFTPClientConfig());
// UNIX parsing by default if no suitable parser found } else {
ftpClient.configure(new FTPClientConfig(FTPClientConfig.SYST_UNIX)); // UNIX parsing by default if no suitable parser found
} ftpClient.configure(new FTPClientConfig(FTPClientConfig.SYST_UNIX));
}
if (_isPassiveDataConnectionMode) { if (_isPassiveDataConnectionMode) {
ftpClient.enterLocalPassiveMode(); ftpClient.enterLocalPassiveMode();
} }
if (isBinary) { if (isBinary) {
ftpClient.setFileType(FTP.BINARY_FILE_TYPE); ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
} else { } else {
ftpClient.setFileType(FTP.ASCII_FILE_TYPE); ftpClient.setFileType(FTP.ASCII_FILE_TYPE);
}
ftpClient.registerSpyStream(_ftpLoggingOutputStream);
ok=true;
} finally {
//disconnect the erroneous ftpClient, but forward the exception
if (!ok) {
try {
ftpClient.disconnect();
} catch(Throwable t) { /*ignore*/ }
}
} }
ftpClient.registerSpyStream(_ftpLoggingOutputStream);
return ftpClient; return ftpClient;
} }
@ -1350,10 +1357,10 @@ public class FTPService extends AbstractFileService implements IFileService, IFT
FTPClient ftpClient = cloneFTPClient(isBinary); FTPClient ftpClient = cloneFTPClient(isBinary);
ftpClient.changeWorkingDirectory(remoteParent); ftpClient.changeWorkingDirectory(remoteParent);
stream = new FTPBufferedInputStream(ftpClient.retrieveFileStream(remoteFile), ftpClient); stream = new FTPBufferedInputStream(ftpClient.retrieveFileStream(remoteFile), ftpClient);
} }
catch (Exception e) { catch (Exception e) {
throw new RemoteFileIOException(e); throw new RemoteFileIOException(e);
} }
return stream; return stream;
} }