ftp directory with spaces

Support for PocketPC and WinCE version

Moderators: white, Hacker, petermad, Stefan2

Xorgeo
Junior Member
Junior Member
Posts: 9
Joined: 2008-05-05, 14:35 UTC

ftp directory with spaces

Post by *Xorgeo »

I noticed a bug in how the TC CE ftp plugin handles spaces in a directory name.

When running the ftp plugin and changing to a directory with a space in it's name, TC does not list any of the files in the directory.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Unfortunately many FTP servers do not support listing directories with spaces in the name. The FTP plugin lists directories like this:
LIST /path/to/directory/name

I tried both
LIST /dir with space
and
LIST "/dir with space"

but it didn't work.
Author of Total Commander
https://www.ghisler.com
Xorgeo
Junior Member
Junior Member
Posts: 9
Joined: 2008-05-05, 14:35 UTC

Using XP ftp

Post by *Xorgeo »

If I use a different client, such as the Windows XP ftp client, it will display all of the files in a directory with a space. TC CE does not.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

TC for Windows works completely differently: It uses the CWD (change working directory) command to switch to the directory, and then send the LIST command. It seems that some servers support spaces in CWD but not in LIST. Unfortunately it's not possible to switch to this method because the FTP plugin has to use relative paths relative to the plugin root. Using the CWD command could cause redirections (links) or lead to directories which are even above the starting location...
Author of Total Commander
https://www.ghisler.com
Xorgeo
Junior Member
Junior Member
Posts: 9
Joined: 2008-05-05, 14:35 UTC

Post by *Xorgeo »

ghisler(Author) wrote:TC for Windows works completely differently: It uses the CWD (change working directory) command to switch to the directory, and then send the LIST command.
The ftp protocol is the same for both the Windows XP ftp and TC CE ftp.

I did a Wireshark capture of a Windows XP ftp session and it also issues the ftp CWD. PORT, and LIST ftp commands (without any ASCII quotes).

For my example the ftp commands to the server were:
CWD Cha File\r\n
PORT 10,10,10,10,19,142\r\n
LIST\r\n
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

No, it's not the same! TC CE uses the absolute path in the LIST command:
LIST /path
Author of Total Commander
https://www.ghisler.com
User avatar
Hacker
Moderator
Moderator
Posts: 13052
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Post by *Hacker »

Christian,
That leads us to two questions:
1. Why does TC CE not use CWD?
2. Does LIST work when escaping spaces, like LIST /dir\ with\ space?

Roman
Mal angenommen, du drückst Strg+F, wählst die FTP-Verbindung (mit gespeichertem Passwort), klickst aber nicht auf Verbinden, sondern fällst tot um.
Xorgeo
Junior Member
Junior Member
Posts: 9
Joined: 2008-05-05, 14:35 UTC

Post by *Xorgeo »

ghisler(Author) wrote:No, it's not the same! TC CE uses the absolute path in the LIST command:
LIST /path
The protocol is defined in RFC 959 and RFC 3659
http://tools.ietf.org/html/rfc959
http://tools.ietf.org/html/rfc3659

I have never seen TC CE list the contents of the files in a directory when it has a space in it's name. There are plenty of examples of clients that do list the files.

I did a Airscanner Sniffer capture of TC CE ftp session. It showed the client:
PASV\r\n
LIST /pub/depot/Cha File/\r\n

Note that the Windows XP ftp client did:
LIST Cha File\r\n
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

I have already explained above why I can't use CWD:
Unfortunately it's not possible to switch to this method because the FTP plugin has to use relative paths relative to the plugin root. Using the CWD command could cause redirections (links) or lead to directories which are even above the starting location...
Author of Total Commander
https://www.ghisler.com
Xorgeo
Junior Member
Junior Member
Posts: 9
Joined: 2008-05-05, 14:35 UTC

Post by *Xorgeo »

ghisler(Author) wrote:Unfortunately many FTP servers do not support listing directories with spaces in the name.
If you were to use the ftp CWD, wouldn't you just have to keep track (store) of the 2 absolute paths for reconstruction, namely:
The absolute path to the ftp plugin-account and the ftp CWD path.

Then when referencing the ftp relative path, the absolute path could be reconstructed via:
/plugin/ftp/account/ftp-cwd

By using CWD, it appears that the listing of directories with spaces problem could be avoided.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

The problem is with symbolic links, they can transfer you ANYWHERE, so PWD would return a completely different location...
Author of Total Commander
https://www.ghisler.com
Xorgeo
Junior Member
Junior Member
Posts: 9
Joined: 2008-05-05, 14:35 UTC

Post by *Xorgeo »

ghisler(Author) wrote:The problem is with symbolic links, they can transfer you ANYWHERE, so PWD would return a completely different location...
If you did not use PWD, remember the path that the user selected, and use CWD, wouldn't that solve both problems?
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Not necessarily - for example, if the user goes down to a directory and then up (CWD .. or CDUP), the path could be something different from where the user came when he followed a symbolic link. Of course I could try to use CWD with full path, but this would probably have the same problems with spaces as using LIST with full path...
Author of Total Commander
https://www.ghisler.com
Xorgeo
Junior Member
Junior Member
Posts: 9
Joined: 2008-05-05, 14:35 UTC

Post by *Xorgeo »

ghisler(Author) wrote:Not necessarily - for example, if the user goes down to a directory and then up (CWD .. or CDUP), the path could be something different from where the user came when he followed a symbolic link. Of course I could try to use CWD with full path, but this would probably have the same problems with spaces as using LIST with full path...
How about doing a PWD after any user directed CWD .. or CDUP, then replacing the user selected path with the PWD response.

This way both the LIST directory space and the symbolic link problems would be averted.
Xorgeo
Junior Member
Junior Member
Posts: 9
Joined: 2008-05-05, 14:35 UTC

Post by *Xorgeo »

I guess you gave up on me.
Post Reply