View | Details | Raw Unified | Return to bug 199243
Collapse All | Expand All

(-)src/org/eclipse/rse/internal/services/files/ftp/FTPService.java (-33 / +58 lines)
Lines 69-74 Link Here
69
import java.io.IOException;
69
import java.io.IOException;
70
import java.io.InputStream;
70
import java.io.InputStream;
71
import java.io.OutputStream;
71
import java.io.OutputStream;
72
import java.net.SocketException;
72
import java.text.MessageFormat;
73
import java.text.MessageFormat;
73
import java.util.ArrayList;
74
import java.util.ArrayList;
74
import java.util.HashMap;
75
import java.util.HashMap;
Lines 164-169 Link Here
164
		public void close() throws IOException {
165
		public void close() throws IOException {
165
			super.close();
166
			super.close();
166
			client.completePendingCommand();
167
			client.completePendingCommand();
168
			client.logout();
167
		}
169
		}
168
	}
170
	}
169
	
171
	
Lines 199-204 Link Here
199
		public void close() throws IOException {
201
		public void close() throws IOException {
200
			super.close();
202
			super.close();
201
			client.completePendingCommand();
203
			client.completePendingCommand();
204
			client.logout();
202
		}
205
		}
203
	}
206
	}
204
	
207
	
Lines 411-416 Link Here
411
		return _ftpClient; 
414
		return _ftpClient; 
412
	}
415
	}
413
	
416
	
417
	
418
	private FTPClient cloneFTPClient(boolean isBinary)
419
	{
420
		
421
		FTPClient ftpClient = new FTPClient();
422
		try {
423
			ftpClient.connect(_ftpClient.getRemoteAddress());
424
			ftpClient.login(_userId,_password);
425
			
426
			if (_clientConfigProxy != null) {
427
				ftpClient.configure(_clientConfigProxy.getFTPClientConfig());
428
			} else {
429
				// UNIX parsing by default if no suitable parser found
430
				ftpClient.configure(new FTPClientConfig(FTPClientConfig.SYST_UNIX));
431
			}
432
433
			if (_isPassiveDataConnectionMode) {
434
				ftpClient.enterLocalPassiveMode();
435
			}
436
437
			if (isBinary) {
438
				ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
439
			} else {
440
				ftpClient.setFileType(FTP.ASCII_FILE_TYPE);
441
			}
442
			
443
			ftpClient.registerSpyStream(_ftpLoggingOutputStream);
444
445
		} catch (Exception e) {}
446
		
447
		
448
		return ftpClient;
449
	}
450
	
451
	private void disconnect(FTPClient ftpClient)
452
	{
453
		ftpClient.registerSpyStream(null);
454
		try {
455
			ftpClient.logout();
456
		} catch (IOException e) {}
457
	}
458
	
414
	/*
459
	/*
415
	 * (non-Javadoc)
460
	 * (non-Javadoc)
416
	 * @see org.eclipse.rse.services.files.IFileService#getFile(String, String, IProgressMonitor)
461
	 * @see org.eclipse.rse.services.files.IFileService#getFile(String, String, IProgressMonitor)
Lines 1305-1333 Link Here
1305
1350
1306
		InputStream stream = null;
1351
		InputStream stream = null;
1307
		
1352
		
1308
		if(_commandMutex.waitForLock(monitor, Long.MAX_VALUE))
1353
		try {
1309
		{
1354
			FTPClient ftpClient = cloneFTPClient(isBinary);
1310
			try {
1355
			ftpClient.changeWorkingDirectory(remoteParent);
1311
				FTPClient ftpClient = getFTPClient();
1356
			stream = new FTPBufferedInputStream(ftpClient.retrieveFileStream(remoteFile), ftpClient);
1312
				ftpClient.changeWorkingDirectory(remoteParent);
1313
				setFileType(isBinary);
1314
				stream = new FTPBufferedInputStream(ftpClient.retrieveFileStream(remoteFile), ftpClient);
1315
			}
1357
			}
1316
			catch (Exception e) {			
1358
			catch (Exception e) {			
1317
				throw new RemoteFileIOException(e);
1359
				throw new RemoteFileIOException(e);
1318
			}finally {
1319
				//TODO I am not 100% sure but I _think_ that the _commandMutex
1320
				//may only be released once reading the stream is complete,
1321
				//since in FTPBufferedInputStream.close() a pending command
1322
				//is being sent.
1323
				//After all, the safer solution would be to have a separate
1324
				//FTP client connection to the remote for the download, such 
1325
				//that dir channel remains free. See bug #198636
1326
				_commandMutex.release();
1327
			}
1360
			}
1328
		} else {
1361
			
1329
			throw new RemoteFileCancelledException();
1330
		}
1331
		return stream;
1362
		return stream;
1332
	}
1363
	}
1333
1364
Lines 1343-1362 Link Here
1343
		
1374
		
1344
		OutputStream stream = null;
1375
		OutputStream stream = null;
1345
		
1376
		
1346
		if(_commandMutex.waitForLock(monitor, Long.MAX_VALUE))
1377
		try {
1347
		{
1378
			FTPClient ftpClient = cloneFTPClient(isBinary);
1348
			try {
1379
			clearCache(remoteParent);
1349
				FTPClient ftpClient = getFTPClient();
1380
			ftpClient.changeWorkingDirectory(remoteParent);
1350
				clearCache(remoteParent);
1381
			stream = new FTPBufferedOutputStream(ftpClient.storeFileStream(remoteFile), ftpClient);
1351
				ftpClient.changeWorkingDirectory(remoteParent);
1382
		}
1352
				setFileType(isBinary);
1383
		catch (Exception e) {
1353
				stream = new FTPBufferedOutputStream(ftpClient.storeFileStream(remoteFile), ftpClient);
1384
			throw new RemoteFileIOException(e);
1354
			}
1355
			catch (Exception e) {
1356
				throw new RemoteFileIOException(e);
1357
			}finally {
1358
				_commandMutex.release();
1359
			}
1360
		}
1385
		}
1361
		
1386
		
1362
		return stream;
1387
		return stream;

Return to bug 199243