Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
5.5k views
in Java FTP by (820 points)
I have a directory on an FTP server, I can connect fine, but when I try and list the dir via directoryList("/path/to/dir") it gives me an array of size 0. There is definitely 1 file there, which I just uploaded with WinSCP. I've used this code many times before, but the only difference I can think of is that the directory path has spaces in it. When I replace the spaces with underscores, it works perfectly fine, no problems.

When I try using directoryNameList("/path/to/dir",false) I get an array with the expected filenames, but when I use directoryNameList("/path/to/dir",true), it gives me back each of the pieces that were separated by spaces as errors (from the ftpd). Even when I try and escape the spaces (e.x. "/path/to\\ dir\\ with\\ spaces/") it gives me the same thing. If I try and escape using directoryList(), it still gives me 0 results.

Here's some of the output from the logs when I set -Dedtftp.log.log4j=true
2011-10-17 12:22:10,387 INFO  [   ] FTPTaskProcessor - Freed connection for task 1
2011-10-17 12:22:10,388 INFO  [   ] FTPTaskProcessor - Task 1 complete (FTPThread[FTPThread_edt_4])
2011-10-17 12:22:14,855 INFO  [   ] FTPTaskProcessor - Processing task 2:ListDirectory[/UNI_webvotes/Protagonistas Mobile Web - MIA]
2011-10-17 12:22:15,080 INFO  [   ] FTPControlSocket - Substituting server supplied IP (X.X.X.X) with remote host IP (X.X.X.X)
2011-10-17 12:22:15,205 WARN  [   ] FTPFileFactory - Could not detect format. Using default UNIX
2011-10-17 12:22:15,268 INFO  [   ] FTPTaskProcessor - Processed task 2:ListDirectory[/]
2011-10-17 12:22:15,268 INFO  [   ] FTPTaskProcessor - Freed connection for task 2
2011-10-17 12:22:15,269 INFO  [   ] FTPTaskProcessor - Task 2 complete (FTPThread[FTPThread_edt_0])
2011-10-17 12:22:41,645 INFO  [   ] FTPTaskProcessor - Processing task 3:ListDirectory[/UNI_webvotes/Protagonistas_Mobile_Web_MIA]
2011-10-17 12:22:42,663 INFO  [   ] FTPControlSocket - Substituting server supplied IP (X.X.X.X) with remote host IP (X.X.X.X)
2011-10-17 12:22:43,919 INFO  [   ] FTPTaskProcessor - Processed task 3:ListDirectory[/]
2011-10-17 12:22:43,919 INFO  [   ] FTPTaskProcessor - Freed connection for task 3
2011-10-17 12:22:43,920 INFO  [   ] FTPTaskProcessor - Task 3 complete (FTPThread[FTPThread_edt_3])


EDIT: Verified this problem also exists with 3.9.1.

6 Answers

0 votes
by (162k points)
A debug level log will help diagnose the problem. It could be that the server doesn't cope with the path. Try changing into the directory first, and not supplying the path when you get the listing.
0 votes
by (820 points)
This is the directoryList(dirPath), then directoryNameList(dirPath,false), then directoryNameList(dirPath,true)


2011-10-18 11:05:44,226 DEBUG [BaffA-PC] FTPTaskProcessor - Using the master context
2011-10-18 11:05:44,226 DEBUG [BaffA-PC] FTPTaskProcessor - Added task 4 to the queue for processing
2011-10-18 11:05:44,226 INFO  [   ] FTPTaskProcessor - Processing task 4:ListDirectory[/UNI_webvotes2/Protagonistas Mobile Web - MIA]
2011-10-18 11:05:44,226 DEBUG [BaffA-PC] AsyncResult - waitTillComplete() called: com.enterprisedt.net.ftp.async.DirectoryListResult@353e58cd
2011-10-18 11:05:44,226 DEBUG [   ] FTPConnectionPool - Got a free connection: FTPConnection #1(0 left)
2011-10-18 11:05:44,226 DEBUG [   ] FTPClient - keepAlive() called
2011-10-18 11:05:44,226 DEBUG [BaffA-PC] AsyncResult - Waiting until operation complete - com.enterprisedt.net.ftp.async.DirectoryListResult
2011-10-18 11:05:44,226 DEBUG [   ] FTPControlSocket - ---> NOOP
2011-10-18 11:05:44,473 DEBUG [   ] FTPControlSocket - 200 NOOP command successful.
2011-10-18 11:05:44,474 DEBUG [   ] Task - Remote directory unchanged [/]
2011-10-18 11:05:44,474 DEBUG [   ] Task - Setting detect transfer mode to false
2011-10-18 11:05:44,477 DEBUG [   ] FTPControlSocket - ---> PWD
2011-10-18 11:05:44,655 DEBUG [   ] FTPControlSocket - 257 "/" is current directory.
2011-10-18 11:05:44,655 DEBUG [   ] FTPClient - setupDirDetails(/UNI_webvotes2/Protagonistas Mobile Web - MIA) returning: ///UNI_webvotes2/Protagonistas Mobile Web - MIA
2011-10-18 11:05:44,655 DEBUG [   ] ProFTPControlSocket - Checking if IPV6:java.net.Inet4Address (W.X.Y.Z)
2011-10-18 11:05:44,656 DEBUG [   ] FTPControlSocket - ---> PASV
2011-10-18 11:05:44,848 DEBUG [   ] FTPControlSocket - 227 Entering Passive Mode (W,X,Y,Z,209,44)
2011-10-18 11:05:44,849 INFO  [   ] FTPControlSocket - Substituting server supplied IP (W.X.Y.Z) with remote host IP (W.X.Y.Z)
2011-10-18 11:05:44,849 DEBUG [   ] StreamSocketFactory - Connecting to W.X.Y.Z:53548 via standard socket
2011-10-18 11:05:45,294 DEBUG [   ] FTPControlSocket - ---> LIST /UNI_webvotes2/Protagonistas Mobile Web - MIA
2011-10-18 11:05:45,682 DEBUG [   ] FTPControlSocket - 150 Opening BINARY mode data connection for '/bin/ls'.
2011-10-18 11:05:45,682 DEBUG [   ] FTPClient - ftpd: -: No such file or directory
2011-10-18 11:05:45,682 DEBUG [   ] FTPClient - ftpd: /UNI_webvotes2/Protagonistas: No such file or directory
2011-10-18 11:05:45,683 DEBUG [   ] FTPClient - ftpd: MIA: No such file or directory
2011-10-18 11:05:45,683 DEBUG [   ] FTPClient - ftpd: Mobile: No such file or directory
2011-10-18 11:05:45,683 DEBUG [   ] FTPClient - ftpd: Web: No such file or directory
2011-10-18 11:05:45,684 DEBUG [   ] FTPControlSocket - 226 Transfer complete.
2011-10-18 11:05:45,705 DEBUG [   ] UnixFileParser - Not in UNIX format
2011-10-18 11:05:45,706 DEBUG [   ] UnixFileParser - Not in UNIX format
2011-10-18 11:05:45,707 DEBUG [   ] WindowsFileParser - Not in Windows format
2011-10-18 11:05:45,708 DEBUG [   ] VMSFileParser - Not in VMS format
2011-10-18 11:05:45,708 DEBUG [   ] NetwareFileParser - Not in Netware format
2011-10-18 11:05:45,708 WARN  [   ] FTPFileFactory - Could not detect format. Using default UNIX
2011-10-18 11:05:45,708 DEBUG [   ] FTPControlSocket - ---> PWD
2011-10-18 11:05:46,023 DEBUG [   ] FTPControlSocket - 257 "/" is current directory.
2011-10-18 11:05:46,023 DEBUG [   ] AsyncResult - notifyComplete() called: com.enterprisedt.net.ftp.async.DirectoryListResult@353e58cd
2011-10-18 11:05:46,024 DEBUG [   ] AsyncResult - waitTillComplete() called: com.enterprisedt.net.ftp.async.DirectoryListResult@353e58cd
2011-10-18 11:05:46,024 DEBUG [BaffA-PC] AsyncResult - waitTillComplete() exit: com.enterprisedt.net.ftp.async.DirectoryListResult@353e58cd
2011-10-18 11:05:46,025 DEBUG [   ] AsyncResult - waitTillComplete() exit: com.enterprisedt.net.ftp.async.DirectoryListResult@353e58cd
2011-10-18 11:05:46,025 INFO  [   ] FTPTaskProcessor - Processed task 4:ListDirectory[/]
2011-10-18 11:05:46,025 INFO  [   ] FTPTaskProcessor - Freed connection for task 4
2011-10-18 11:05:46,025 INFO  [   ] FTPTaskProcessor - Task 4 complete (FTPThread[FTPThread_edt_3])
2011-10-18 11:05:55,193 DEBUG [   ] FTPTaskProcessor - Sleeping for 30000 ms
2011-10-18 11:06:25,195 DEBUG [   ] FTPTaskProcessor - Calling keepAlive() on stale connection FTPConnection #1 (maxtime=1318961146025)
2011-10-18 11:06:25,195 DEBUG [   ] FTPClient - keepAlive() called
2011-10-18 11:06:25,196 DEBUG [   ] FTPControlSocket - ---> PWD
2011-10-18 11:06:25,437 DEBUG [   ] FTPControlSocket - 257 "/" is current directory.
2011-10-18 11:06:25,437 DEBUG [   ] FTPTaskProcessor - Sleeping for 30000 ms
2011-10-18 11:06:31,337 DEBUG [BaffA-PC] FTPTaskProcessor - Using the master context
2011-10-18 11:06:31,338 DEBUG [BaffA-PC] FTPTaskProcessor - Added task 5 to the queue for processing
2011-10-18 11:06:31,338 INFO  [   ] FTPTaskProcessor - Processing task 5:ListDirectory[/UNI_webvotes2/Protagonistas Mobile Web - MIA]
2011-10-18 11:06:31,338 DEBUG [BaffA-PC] AsyncResult - waitTillComplete() called: com.enterprisedt.net.ftp.async.DirectoryNameListResult@65c7bbfc
2011-10-18 11:06:31,338 DEBUG [   ] FTPConnectionPool - Got a free connection: FTPConnection #1(0 left)
2011-10-18 11:06:31,339 DEBUG [BaffA-PC] AsyncResult - Waiting until operation complete - com.enterprisedt.net.ftp.async.DirectoryNameListResult
2011-10-18 11:06:31,339 DEBUG [   ] FTPClient - keepAlive() called
2011-10-18 11:06:31,339 DEBUG [   ] FTPControlSocket - ---> PWD
2011-10-18 11:06:31,637 DEBUG [   ] FTPControlSocket - 257 "/" is current directory.
2011-10-18 11:06:31,637 DEBUG [   ] Task - Remote directory unchanged [/]
2011-10-18 11:06:31,638 DEBUG [   ] Task - Setting detect transfer mode to false
2011-10-18 11:06:31,638 DEBUG [   ] ProFTPControlSocket - Checking if IPV6:java.net.Inet4Address (W.X.Y.Z)
2011-10-18 11:06:31,638 DEBUG [   ] FTPControlSocket - ---> PASV
2011-10-18 11:06:31,968 DEBUG [   ] FTPControlSocket - 227 Entering Passive Mode (W,X,Y,Z,215,13)
2011-10-18 11:06:31,969 INFO  [   ] FTPControlSocket - Substituting server supplied IP (W.X.Y.Z) with remote host IP (W.X.Y.Z)
2011-10-18 11:06:31,969 DEBUG [   ] StreamSocketFactory - Connecting to W.X.Y.Z:55053 via standard socket
2011-10-18 11:06:32,246 DEBUG [   ] FTPControlSocket - ---> NLST /UNI_webvotes2/Protagonistas Mobile Web - MIA
2011-10-18 11:06:32,609 DEBUG [   ] FTPControlSocket - 150 Opening BINARY mode data connection for 'file list'.
2011
0 votes
by (162k points)
The server can't cope with the path you are supplying. It is returning this message:

ftpd: -: No such file or directory
ftpd: /UNI_webvotes2/Protagonistas: No such file or directory
ftpd: MIA: No such file or directory
ftpd: Mobile: No such file or directory
ftpd: Web: No such file or directory

You need to change into the directory and then do the list on ""
0 votes
by (820 points)
Ah, so, the problem is that the /bin/ls isn't operating on the entire text string of the directory path? There's no way to escape the spaces (or other special characters) to have it work correctly?

--Aaron
0 votes
by (162k points)
Yes, that's what's happening. You could try escaping the path - see if you can put escaped quotes around it.
0 votes
by (820 points)
Ah, that's the 1 thing I didn't try. I tried using "\\ " to escape the space, but not escaped double quotes around the entire path.

Categories

...