FTP client cannot distinguish files from directories

Hi wmusers! I needed some advice on a FTP client problem.

I have a custom FTP client to pickup files from specified directories on multiple remote partner FTP servers. The code looks simple enough:

INVOKE pub.client.ftp:ls  (returns list of files in output 'dirlist' variable) 
LOOP     (loop over returned 'dirlist') 
   INVOKE pub.client.ftp:get   (retrieve each entry)

The problem is some remote partners have some subdirectory under their specified ‘remote-pickup’ directory. The list of files returned by ‘pub.client.ftp:ls’ does not distinguish files from directories. A remote directory looks just like a filename and ‘pub.client.ftp:get’ throws an exception trying to retrieve a directory.

Any thoughts on how to workaround this problem?

There is a ‘pub.client.ftp:dir’ command that returns additional information but the format seems dependent on the remote FTP server.

Maybe this is not a viable answer for your particular business problem, but in similar cases, I have used pub.client.ftp:mget with the filenamepattern set. It only gets the files and only gets the ones matching the pattern. If you don’t have a set pattern for name or extension, use .. That’ll get all files, but ignore directories.

For that matter, setting filenamepattern=. on your pub.client.ftp:ls should achieve the same thing (though mget is faster).

But it occurs to me that perhaps you need to traverse the directories as well, not ignore them in favor of the files at the root dir level? Is that true?

Sorry for all the posts on this everyone, but this got me thinking about my current implementation and how it could be improved.

Here’s an FTP flow that will get back the directories and files, retrieve all the files for the parent directory, then traverse the all the subdirectories and retrieve their files.

pub.client.ftp:login
pub.client.ftp:dir (retrieves detailed list of all files and directories)
LOOP on /dirlist
BRANCH on /dirlist
/^-/ SEQUENCE (regex to pick the files)
pub.string:tokenize (tokenize current dirlist detail into valueList)
pub.client.ftp:get (with local and remotefile set to %valueList[8]%)
/^d/ SEQUENCE (regex to pick the dirs)
pub.string:tokenize (tokenize current dirlist detail into valueList)
pub.client.ftp:cd (with dirpath set to %valueList[8]%)
(AND THEN REPEAT EVERYTHING FROM pub.client.ftp:dir ABOVE for this dir)

I’m sure I could make this more efficient with some time (I’d likely modularize the repeated section), but it’s back to the grindstone for now.

Hope this helps start someone’s thinking on this problem when they encounter it.