Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
5.8k views
in .NET FTP by (1.8k points)
Hi,

Following a mail your support team sent me a number of weeks ago, I wanted to try one of your suggestions, but I ran into some problems:

I was wondering if it is possible to use the -R switch when listing a directory.
I tried using the InvokeFTPCommand method.
This returns a 150, but I need off course the response with the itterative listing after that.
How is this obtained?

With ftp.exe, I can type ls -R and then it gives me a complete deep listing of the current directory in about 50 seconds.
If I'm not mistaking the current GetFileInfos method does not make use of the itterative listing switch, correct?

I know it is not implemented on all servers, but I would like to do a try with the R switch, and if that fails, failover to the regular method.
The time gained by that check outrules the possible delay by using it on a server that doesn't support it in my opinion.

10 Answers

0 votes
by (51.6k points)
Hi Boris

The best way to do this is to call the GetFiles method with the -R switch as an argument:
ftpConnection.ServerDirectory = "mydirectory";
string[] rawListing = ftpConnection.GetFiles("-R");

rawListing should then contain the same output that you get on the command-line. You can then parse the array to obtain the entire directory structure.

- Hans (EnterpriseDT)
0 votes
by (1.8k points)
Aha, great!
Thx.
0 votes
by (1.8k points)
How does the GetFileInfos get its full file information?
Can this be used in combination with the -R option?
0 votes
by (162k points)
It uses the LIST command. Some servers support using -R with LIST.
0 votes
by (1.8k points)
-edit: double post
0 votes
by (1.8k points)
What I want to obtain is a recursive GetFileInfos that uses the -R option if it is available and falls back to the current method if not.
I've seen that the edt library exposes it's file info parser, so I thought I could just use the list -R method and pass it's result to a method that cuts the result into pieces the GetFileInfos understands.

Is this possible to do?

It seems like something everybody could benefit from as the -R function requires just one single call and does all the itterative work on server side.
Which is way more performant than doing the "directory shuffle" by client requests.
If I'm not mistaking the EDT's sync functionality relies on the GetFileInfos method.
So improving the GetFileInfos performance and functionality would also cascade in the sync methods.
0 votes
by (51.6k points)
Using FTPFileFactory directly is a good idea, but you'll need to preprocess the raw listing before you can do it. The result of a LIST -R command is a bunch of directory listings joined together. They are separated by blank lines and each is preceded by the path of the directory that is being listed. You'll need to separate out each individual listing (by searching for blank lines) and use the path to figure out where it fits into the directory-tree. This is going to take a bit of work, but it doesn't seem to me like a particularly difficult task. Once you've separated them into individual listings you can pass them to an instance of FTPFileFactory, which should be able to parse them and create FTPFile objects.

As for adding this functionality to our product, we have considered doing so, but are worried about reliability. The reason for this is that it seems that some server simply ignore the -R flag and return a non-recursive listing. It may be impossible to detect whether it's ignored the flag or whether the subdirectories are empty.

For example, the MS FTP site (ftp.microsoft.com) sometimes supports LIST -R and sometimes doesn't. I guess it depends on which particular machine your session gets handled by. Just now I logged in and changed to /bussys/backoffice and executed a LIST -R command. It returned
02-01-06  03:01PM       <DIR>          reskit
02-01-06  03:01PM       <DIR>          SMS

Does this mean that LIST -R doesn't work this time? Or does it mean that the directories reskit and SMS are both empty? I'm not sure.

It may be that there is something we can use to reliably tell whether or not it's working on this server, but the fact is that LIST -R is a non-standard feature and that it is therefore likely to be implemented differently on different servers. In contrast, the recursive listing approach relies on no non-standard features and is therefore much more likely to work reliably.

Your problem is a very rare one because it's a confluence of three conditions:
  1. A very large directory tree.
  2. A very short time-out.
  3. A server has a policy that causes it to time out unless actual file transfers take place.

In my opinion the time-out policy is a mistake, especially given the size of the directory trees on the server and the task that's required of it. This policy should be changed, but I realize that it may not be possible for your to affect this change.

If you decide against the LIST -R approach then it seems to me that the best solution is to transfer a file after each directory listing. If you wish to do this then we are happy to provide you with advice and even write some of the code for you. Please let us know if you would like to try it.

- Hans (EnterpriseDT)
0 votes
by (1.8k points)
Well, I already implemented the bogus-file-upload solution.
But the process just takes an impractical(sp?) time to complete on a whole.

I didn't know that some servers replied with a regular LIST upon unsupported LIST -R request.
So indeed, that would be too error prone. I have been looking for a command that returns all supported commands but if it exists at all, that too seems to be a non-standard function. Not too illogical now that I come to think off it.
Negatiations with that host are (still) in progress, and I do hope my client will get the host to upgrade/reconfigure its server or just change host.
In the meanwhile the process is ran on a local file system. The process difference for the whole service whent from 1 day to 3 minutes.
This cannot be a final solution though. So in the (near) future I will have need for this -R function.

But actually this post was not related to that problem.
I was merely trying to improve the sync functionality since my next project will use it extensively.
For this project I know on beforehand how the server is configured. So I can know (by manual testing if nessecary) if the -R function is supported.
So what I need to know is if there is an (easy) way to feed the FileInfos I got from the FileFactory to the Synchronize method.

Thx for your feedback.
Although the whole FTP story makes me brain want to flee, I do appreciate the support I get from EDT a lot.
If you would ever come up with an idea to figure out a way to know to what degree the LIST -R function is supported, please give me a sign.
I would be very interested in that.
0 votes
by (51.6k points)
Well, I already implemented the bogus-file-upload solution.
But the process just takes an impractical(sp?) time to complete on a whole.

You could probably speed it up by cancelling the transfer as soon as a few bytes have been transferred instead of waiting for the whole file to be transferred. This may be done by handling the BytesTransferred event and calling CancelTransfer inside it.
So what I need to know is if there is an (easy) way to feed the FileInfos I got from the FileFactory to the Synchronize method.

No sorry, the synchronization functionality wasn't designed to be used like that.

- Hans (EnterpriseDT)
0 votes
by (1.8k points)
No sorry, the synchronization functionality wasn't designed to be used like that.

Fair enough

Categories

...