Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
15k views
in .NET FTP by
Hi there. What methods/properties would I use in the FTPClient to recursively loop through a folder and delete all files/subfolders in it.

It looks like Dir or DirDetails might be something like what I'm looking for. Basically, I just need a method that will list the subdirectories, and a method that will list the files.


WATYF

16 Answers

0 votes
by
Sorry... my bad again... I worked it out (jumping the gun a lot today. :P).


But I did run into an error while doing this. I used DirDetails to loop through the files in the directory... but sometimes (like when I manually drop a new file into one of the FTP folders) it doesn't "detect" the files properly... it just says that they're not there.

Here's a example... I was stepping through my recursive loop, and I got to the end of a group of subdirectories and I tried to list the files in the last folder... DirDetails said there were 0 files (even though there was one).... but "Dir" did detect the file. I double checked the results in the Immediate Window, as you can see below... DirDetails and Dir, called at the same time, using the same folder, return different results.

[ img ]

Obviously, I would use Dir if I could, but I need to be able to differentiate between a file and a folder (which I don't think I can do using Dir).

Any ideas?


WATYF
0 votes
by (161k points)
They shouldn't - if you can log in from a commandline client and type 'dir' and post the results, we can test it out.

If you can post the log file that might help also.

BTW for those who don't wish to implement recursive deletes etc, edtFTPnet/PRO does support some useful recursive methods like this.

DirDetails and Dir, called at the same time, using the same folder, return different results.
0 votes
by
Here's the results of a command line Dir of that folder... again.. it returns one file in the results. If I use DirDetails (still) is returns no results.

[ img ]



WATYF
0 votes
by (161k points)
Can you copy & paste as text? Then we can put it in a file and test it. Thanks.

Here's the results of a command line Dir of that folder... again.. it returns one file in the results. If I use DirDetails (still) is returns no results.

[ img ]



WATYF
0 votes
by
Well.. I'll have to wait till I can get home and create a test user for you (can't do it from here).

A bit of further infomation for now... I tried using the ftp.Dir method with the "full" argument set to "True" and it returned no results... so that's kinda odd. The same folder pulls up a result with the Dir method and "full" set to "False".

Here's a shot of it:
[ img ]



WATYF
0 votes
by
Here's the test from the FTP session...

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

ftp> open www.watyf.com 21
Connected to watyf.com.
220---------- Welcome to Pure-FTPd [TLS] ----------
220-You are user number 1 of 50 allowed.
220-Local time is now 02:38. Server port: 21.
220 You will be disconnected after 15 minutes of inactivity.
User (watyf.com:(none)): ftptest@watyf.com
331 User ftptest@watyf.com OK. Password required
Password: testftp
230-User ftptest@watyf.com has group access to: watyf
230-OK. Current restricted directory is /
230 0 Kbytes used (0%) - authorized: 5120 Kb
ftp> cd C-Drive
250 OK. Current directory is /C-Drive
ftp> cd Temp
250 OK. Current directory is /C-Drive/Temp
ftp> cd "New Folder"
250 OK. Current directory is /C-Drive/Temp/New Folder
ftp> Dir
200 PORT command successful
150 Connecting to port 3156
drwxr-xr-x 2 32309 watyf 4096 Jul 1 21:23 .
drwxr-xr-x 3 32309 watyf 4096 Jul 6 21:39 ..
-rw-r--r-- 1 32309 watyf 5001 Jul 1 21:23 TskSch.log
226-Options: -a -l
226 3 matches total
ftp: 187 bytes received in 0.00Seconds 187000.00Kbytes/sec.
ftp>


The above Dir returns one file... but using DirDetails (and ftp.Dir with "full" set to true) on that same folder returns no files.



WATYF
0 votes
by
I've been trying this out over the last couple days and it appears that this problem is not unique to that one folder. When browsing files/folders that I had uploaded to my server previously using other FTP clients (namely IE), I found that there were many files and folders that weren't visible when using DirDetails.

Please let me know if you find out a cause for this. If you need any more information from me, just let me know. Thanks.



WATYF
0 votes
by (161k points)
Thanks for your assistance. Could you do 2 more listings from your command line client?

Before doing them, type 'debug' to turn verbose debugging on.

1) type 'dir'

2) type 'ls'

This does the two different types of FTP listings.

Many thanks

I've been trying this out over the last couple days and it appears that this problem is not unique to that one folder. When browsing files/folders that I had uploaded to my server previously using other FTP clients (namely IE), I found that there were many files and folders that weren't visible when using DirDetails.

Please let me know if you find out a cause for this. If you need any more information from me, just let me know. Thanks.



WATYF
0 votes
by
Here you go...

I browsed to the same folder again and executed the commands you requested. I have added a subfolder ("Testing") to that folder, in addition to the file ("TaskSch.log") that was already there. Both the "Testing" folder and the "TaskSch.log" file are not visible when using DirDetails from within my application.


ftp> open www.watyf.com
Connected to watyf.com.
220---------- Welcome to Pure-FTPd [TLS] ----------
220-You are user number 2 of 50 allowed.
220-Local time is now 15:33. Server port: 21.
220 You will be disconnected after 15 minutes of inactivity.
User (watyf.com:(none)): ftptest@watyf.com
331 User ftptest@watyf.com OK. Password required
Password:
230-User ftptest@watyf.com has group access to: watyf
230-OK. Current restricted directory is /
230 53 Kbytes used (1%) - authorized: 5120 Kb
ftp> cd C-Drive
250 OK. Current directory is /C-Drive
ftp> cd Temp
250 OK. Current directory is /C-Drive/Temp
ftp> cd "New Folder"
250 OK. Current directory is /C-Drive/Temp/New Folder
ftp> debug
Debugging On .
ftp> dir
---> PORT 172,30,10,47,6,11
200 PORT command successful
---> LIST
150 Connecting to port 39310
drwxr-xr-x 3 32309 watyf 4096 Jul 7 16:05 .
drwxr-xr-x 3 32309 watyf 4096 Jul 7 21:06 ..
drwxr-xr-x 2 32309 watyf 4096 Jul 7 16:05 Testing
-rw-r--r-- 1 32309 watyf 5001 Jul 1 21:23 TskSch.log
226-Options: -a -l
226 4 matches total
ftp: 252 bytes received in 0.00Seconds 252000.00Kbytes/sec.
ftp> ls
---> PORT 172,30,10,47,6,12
200 PORT command successful
---> NLST
150 Connecting to port 42248
.
..
Testing
TskSch.log
226-Options: -a
226 4 matches total
ftp: 28 bytes received in 0.00Seconds 28000.00Kbytes/sec.
ftp>




WATYF
0 votes
by
Did you guys find anything out about this issue? Do you need any more test runs from me? Please let me know. I've found that I can't really use this component unless I get the DirDetails issue fixed, since it doesn't provide an accurate list of files/folders on an FTP server.


WATYF

Categories

...