Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 85257

Summary: FTP can not view subdirectories
Product: [Eclipse Project] Platform Reporter: Sergey Vladimirov <vlsergey>
Component: TeamAssignee: Platform Team Inbox <platform-team-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: blocker    
Priority: P3 Keywords: helpwanted
Version: 3.1   
Target Milestone: 3.1 M7   
Hardware: PC   
OS: Windows 2000   
Whiteboard:
Attachments:
Description Flags
Patch for org/eclipse/ftp/internal/FTPClient.java v1.2
none
Patch for org/eclipse/target/internal/ftp/FtpSite.java v1.2 and org/eclipse/target/internal/ftp/FtpTargetResource.java v1.3 none

Description Sergey Vladimirov CLA 2005-02-15 09:24:11 EST
After adding site to Site explorer:

- site
+-folder1
+-folder2
+-folder3
+-folder4
+-folder5

But after expanding any folder it's lists root directory too:

- site
+-folder1
+-folder2
-+folder3
 +-folder1
 +-folder2
 +-folder3
 +-folder4
 +-folder5
+-folder4
+-folder5

And team sync. doesn't works, becase it listed one directory many times in team 
sync. page, like:
folder1
folder1/folder1
folder1/folder1/folder1
folder1/folder1/folder1/folder1
folder1/folder1/folder1/folder1/folder1, etc.

Manual session log:

[bsp@router bsp]$ ftp
ftp> open somehost
Connected to somehost (*.*.*.*).
220 SERVER FTP Server (vftpd 1.31) ready.
Name (somehost:bsp): ctepa
331 Password required for ctepa.
Password:
230 User ctepa logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> dir
227 Entering passive mode (*,*,*,*,11,46)
150 Opening ASCII mode data connection for /bin/ls
drwx------   1 ftp      users          0 Feb  4 12:54 .
drwx------   1 ftp      users          0 Feb  4 12:54 ..
drwx------   1 ftp      users          0 Feb 15 17:07 Saves
drwx------   1 ftp      users          0 Jan 30 01:13 Scripts
drwx------   1 ftp      users          0 Jan 30 01:13 Web
-rwx------   1 ftp      users     454656 Jan 16 08:46 RunUO.exe
-rwx------   1 ftp      users      53248 Mar 13  2002 zlib.dll
-rwx------   1 ftp      users       2426 Jan  5 18:53 AssemblyInfo.cs
-rwx------   1 ftp      users        499 Feb  4 13:50 Debug RunUO.exe.lnk
-rwx------   1 ftp      users      13730 Jan  3 18:13 changelog.txt
-rwx------   1 ftp      users        851 Dec 29  2004 data_changes.txt
-rwx------   1 ftp      users      18098 Jan  3 18:10 script_changes.txt
-rwx------   1 ftp      users       2142 Jan  3 13:00 README.nix
drwx------   1 ftp      users          0 Jan  7 15:46 Backups
drwx------   1 ftp      users          0 Jan 30 01:12 Data
drwx------   1 ftp      users          0 Jan  2 16:50 Dll
drwx------   1 ftp      users          0 Jan 30 01:13 Logs
-rwx------   1 ftp      users       1376 Feb  4 13:49 Crash 4-2-2005-13-49-
52.log
-rwx------   1 ftp      users       1376 Feb  4 13:50 Crash 4-2-2005-13-50-
23.log
-rwx------   1 ftp      users        854 Feb 12 21:09 Crash 12-2-2005-21-9-
23.log
226 Transfer Complete.
ftp> cd Backups
250 CWD command successful.
ftp> dir
227 Entering passive mode (*,*,*,*,11,47)
150 Opening ASCII mode data connection for /bin/ls
drwx------   1 ftp      users          0 Feb  4 12:55 .
drwx------   1 ftp      users          0 Feb  4 12:55 ..
drwx------   1 ftp      users          0 Feb  4 13:49 Crashed
drwx------   1 ftp      users          0 Feb  4 14:00 Automatic
226 Transfer Complete.
ftp>
Comment 1 Sergey Vladimirov CLA 2005-02-15 09:25:41 EST
Versions of Eclipse and FTP&WebDAV - 3.1M4
Comment 2 Michael Valenta CLA 2005-02-15 09:47:27 EST
The FTP plugin is not being actively developed. Patches will be accepted.
Comment 3 Sergey Vladimirov CLA 2005-02-16 09:10:34 EST
I have no censured words. Just only this fix:

package org.eclipse.ftp.internal;
public class FTPClient implements IClient {
<...>
	public IDirectoryEntry[] listFiles(String directoryPath, boolean 
includeParents, IProgressMonitor monitor) throws FtpException {
		monitor = FtpPlugin.monitorFor(monitor);
		monitor.beginTask(null, 115);
		final String title = FtpPlugin.getResourceString
("FTPClient.listFiles", directoryPath == null ? "." : directoryPath); //$NON-
NLS-1$ //$NON-NLS-2$
		monitor.subTask(title);
		DataConnection manager = null;
		try {
            
            if (directoryPath != null) {
                sendCommand("CWD", directoryPath); //$NON-NLS-1$
                monitor.worked(5);
                switch (readResponseSkip100()) {
                    case 250: 
                        // requested file action ok
                        break;
                    default:
                        defaultResponseHandler();
                }
                monitor.worked(10);
            } else {
                monitor.worked(15);
            }

			// Initiate the data transfer
			manager = initiateDataTransfer("LIST -a", null, false, 
0, FtpPlugin.monitorFor(monitor)); //$NON-NLS-1$
			// Get the input stream from the data connection
			monitor.subTask(FtpPlugin.getResourceString
("FTPClient.transferNoSize", title)); //$NON-NLS-1$

<...>
Comment 4 Sergey Vladimirov CLA 2005-02-16 10:24:52 EST
another fix for another issue.

package org.eclipse.ftp.internal;
<...>
public class FTPClient implements IClient {
<...>
	private InputStream internalGetContents(String filePath, boolean 
binary, long resumeAt, IProgressMonitor monitor) throws FtpException {
		Assert.isNotNull(filePath);

		DataConnection manager = null;
		// send the request to the server
		int tries = 0;
		FtpException lastExc = null;
		while (tries < 3) {
			try {
				manager = initiateDataTransfer(
						"RETR", filePath, binary, 
resumeAt, FtpPlugin.monitorFor(monitor)); //$NON-NLS-1$
				lastExc = null;
			} catch (FtpException exc) {
				lastExc = exc;
			}
			tries++;
			if (lastExc == null) {
				break;
			}
		}
		if (lastExc != null) {
			throw lastExc; 
		}
		InputStream in = manager.getDataTransferInputStream();

		// setup line terminator conversion
		if (! binary && ! Constants.IS_CRLF_PLATFORM) in = new 
CRLFtoLFInputStream(in);
		return in;
	}
<...>
Comment 5 Michael Valenta CLA 2005-02-22 15:03:52 EST
The code in comment #3 breaks the client for me (i.e. I can no longer expand 
my FTP site in the site explorer. I'm not keen on the code in comment #4 
either since all it seems to do is try a few more times.
Comment 6 Sergey Vladimirov CLA 2005-02-25 06:32:41 EST
Can you provide FTP account to test and fix changes?
Comment 7 Michael Valenta CLA 2005-02-25 08:44:58 EST
Sorry, I do not have the ability to do that. However, the ftp server I ran 
against was the obe that ships with RedHat 9.0.
Comment 8 Guillaume Boudreau CLA 2005-02-25 16:48:36 EST
Created attachment 18326 [details]
Patch for org/eclipse/ftp/internal/FTPClient.java v1.2
Comment 9 Guillaume Boudreau CLA 2005-02-25 16:56:49 EST
There is a (probably related) bug that makes the FTP plugin list all 1st level
subdirs of the directory when listing it.
ie opening "home" will make the plugin send all those commands:

LIST -a home/
LIST -a home/backup
LIST -a home/gboudreau
etc.

which takes quite some time to execute...
Comment 10 Guillaume Boudreau CLA 2005-02-25 18:02:53 EST
Created attachment 18327 [details]
Patch for org/eclipse/target/internal/ftp/FtpSite.java v1.2 and org/eclipse/target/internal/ftp/FtpTargetResource.java v1.3

Problem was deeper than I thought...
The TreeView is calling hasChildren() to check if it will display a "+" next to
the item; thus the (mostly) unneeded LIST -a called succesively.
The attached patch 'fix' this by keeping a counter of how many directories
there are under the current directory and skipping the next calls to LIST that
many times after that. Each time a LIST is skipped, a dummy element is returned
so that the TreeView will display a "+" for the item.

For me, the FtpPlugin was unusable without this patch... Listing my /home/pub/
was taking about a minute (~ 40 subdirs)...
Comment 11 Michael Valenta CLA 2005-04-18 14:37:17 EDT
I have submited the fix from comment 8. The fix in comment 10 made some 
assumptions that I didn't feel were safe to release but I found an alternate 
work around for that issue.