Bug 88575 - kio_ftp does not handle files that start or stop with whitespaces
Summary: kio_ftp does not handle files that start or stop with whitespaces
Status: RESOLVED FIXED
Alias: None
Product: kio
Classification: Unmaintained
Component: ftp (show other bugs)
Version: 3.3
Platform: Gentoo Packages Linux
: NOR normal
Target Milestone: ---
Assignee: David Faure
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-09-01 07:54 UTC by Alexander Wigen
Modified: 2011-04-05 23:49 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In: 4.6.2
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Wigen 2004-09-01 07:54:56 UTC
Version:            (using KDE KDE 3.3.0)
Installed from:    Gentoo Packages
OS:                Linux

There is a problem in how the ftp kio slave reads directory listings. Currently it strips whitespaces from the filename (ftp.cc line 1808):

de.name     = remoteEncoding()->decode(tmp.stripWhiteSpace());

Which of course brakes handeling of files that begins or ends with a whitespace.
Comment 1 Nicolas Goutte 2004-09-01 10:24:25 UTC
Do you know any public URL that have such names? (It would be easier to test after fixing the bug.)

Have a nice day!
Comment 2 Alexander Wigen 2004-09-01 17:20:55 UTC
No sorry, I don't have a public URI for such files. I will try to put some up in a couple of days.
Cheers
Comment 3 Alexander Wigen 2004-09-02 08:38:53 UTC
I have been looking at many ftp clients and this seems to be a wide spread problem. One of the clients that get it right is ncftp. ncftp uses a "proxy" ls that also caches the directory structure. Caching would be interesting to implement into this our ftp client.

Filenames with whitespaces like this doesn't happen often but it should still be handled correctly.

The output from LIST varies greatly from site to site but the RFC959 gives us one command for "automatic processing":
NAME LIST (NLST) - This command is intended to return information that can be used by a program to further process the files automatically. The data will be transferred over the data connection as valid pathname strings separated by <CRLF> or <NL>.

One solution is to use the NLST, which gives us a list of all files and dirs in CWD (including dot files, but without any properties). This list could be used in conjunction with the output from LIST (ls -la) to build a correct file listing.

By making an array of files from the output of NLST and searching for their permissions in the output from LIST one could build the file list quite redundantly.

If this is something that is of interest I can start working on a patch.
Cheers
Comment 4 David Faure 2004-09-02 10:18:46 UTC
On Thursday 02 September 2004 08:38, Alexander Wigen wrote:
> I have been looking at many ftp clients and this seems to be a wide spread problem. One of the clients that get it right is ncftp. ncftp uses a "proxy" ls that also caches the directory structure. Caching would be interesting to implement into this our ftp client.
KDirLister implements the caching for us already (in the application side, not in the kioslave; which is even better since kioslaves come and go).

> Filenames with whitespaces like this doesn't happen often but it should still be handled correctly.
> 
> The output from LIST varies greatly from site to site but the RFC959 gives us one command for "automatic processing":
> NAME LIST (NLST) - This command is intended to return information that can be used by a program to further process the files automatically. The data will be transferred over the data connection as valid pathname strings separated by <CRLF> or <NL>.
> 
> One solution is to use the NLST, which gives us a list of all files and dirs in CWD (including dot files, but without any properties). This list could be used in conjunction with the output from LIST (ls -la) to build a correct file listing.
The matching between the two lists sounds a bit difficult in case of discrepancies, but if the
only discrepancy is the space thingie it might work. I'm a bit worried about the performance loss though
(listing everything twice).

> By making an array of files from the output of NLST and searching for their permissions in the output from LIST one could build the file list quite redundantly.

I don't know NLST, but isn't there a way to get one listing "for automatic processing", with all the info?
E.g. does NSLT take options?

Comment 5 Alexander Wigen 2004-09-02 15:32:30 UTC
> KDirLister implements the caching for us already (in the application side, not in the kioslave; which is even better since kioslaves come and go). 
Ah, I didn't know that. After using krusader (which somehow bypasses this) I assumed there was no caching, but when using ftp in konqueror I can see your are right.

> I don't know NLST, but isn't there a way to get one listing "for automatic processing", with all the info? 
> E.g. does NSLT take options?

NLST does not take any options. The problem was addressed in 1994 by Dan Bernstein, he made a draft for "Easily Parsed LIST Format" http://cr.yp.to/ftp/list/eplf.html . This format deals with these problems, but I don't think it's support is very widespread, though Bernstein does list a number of clients supporting it back in '94. The kio slave should support this. For servers not supporting EPLF we have to drop back to the ls format(LIST), but combining LIST and NLST would provide a more robust method.

Please see http://cr.yp.to/ftp/list.html for more info on the problem with ftp directory listing.
Comment 6 Alex Wright 2010-11-06 11:37:54 UTC
Hi,

Is this bug still not fixed?!
Its rather a pain.
If I use command line FTP, I can visually see a space at the start of the filename when using ls. I can use quotes to correctly download the file.

Why can't KDE's ftp work?

At the very least it should be set as a confirmed bug!
Comment 7 Dawit Alemayehu 2011-04-05 23:47:58 UTC
Git commit ba22a1d02382503ca95832a149155e83632c36f6 by Dawit Alemayehu.
Committed on 05/04/2011 at 23:46.
Pushed by adawit into branch 'KDE/4.6'.

Do not trim whitespaces from filenames.

BUG:88575
REVIEW:100943
FIXED-IN:4.6.2

M  +2    -2    kioslave/ftp/ftp.cpp     

http://commits.kde.org/kdelibs/ba22a1d02382503ca95832a149155e83632c36f6
Comment 8 Dawit Alemayehu 2011-04-05 23:49:34 UTC
Git commit 323b2d319b05f31407732972ea9a4013fd706e92 by Dawit Alemayehu.
Committed on 05/04/2011 at 23:53.
Pushed by adawit into branch 'master'.

Do not trim whitespaces from filenames.

CCBUG:88575

(cherry picked from commit ba22a1d02382503ca95832a149155e83632c36f6)

M  +2    -2    kioslave/ftp/ftp.cpp     

http://commits.kde.org/kdelibs/323b2d319b05f31407732972ea9a4013fd706e92