FTP Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsSystem AdministrationFTP Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 20th, 2003, 09:42 AM
ikaros ikaros is offline
PHP Programmer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2000
Posts: 31 ikaros User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 36 m 43 sec
Reputation Power: 9
Send a message via ICQ to ikaros
listing ftp directories

i am developing a site where users are able to browse files and directories stored on an ftp server. it looks a lot like windows explorer, where you have directory listing in a frame to the left.

my problem is that when there are a lot of files, the directory tree takes a LONG time to display (sometimes over 1 minute). the time consuming part is when i retrieve the file list from the ftp server (the parsing part is relatively fast).

if i could just retrieve a list of the directories, and not the files, it would help me a lot i think. does anyone know if this can be done using php's built in ftp functions? or do you have any other suggestions?

Reply With Quote
  #2  
Old May 20th, 2003, 11:36 AM
Viper_SB's Avatar
Viper_SB Viper_SB is offline
Psycho Canadian
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Jan 2001
Location: Canada
Posts: 4,788 Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 4 Weeks 20 h 7 m 56 sec
Reputation Power: 437
PHP Code:
 $FTP_Server "myserver";
$FTP_User "myuser";
$FTP_Pass "mypass";
$dirtolist "/web/";

$ftp ftp_connect($FTP_Server21);
if (
$ftp) {
    if (
ftp_login($ftp$FTP_User$FTP_Pass)) {
        
$dir ftp_rawlist($ftp$dirtolist);
        if (
$dir !== false) {
            foreach (
$dir as $key => $val) {
                
preg_match("/^(d)/"$val$matches);
                if (isset(
$matches[1]) && $matches[1] == "d") {
                    
$dirname substr(strrchr($val" "), 1);
                    print 
"<b>".$dirname."</b> is a directory<br>\n";
                }
            }
        }
    }
} else {
    print 
"Could not connect to FTP site " $FTP_Server ". Please try again later.";
    exit;
}
ftp_quit($ftp); 


Check out ftp_rawlist for more information, also you might want to print out $val in the forloop that way you can see what info it really gives.
Also I know you can get the directory name in the preg_matches also and thus cut out the line $dirname = substr(strrchr($val, " "), 1); and replace it with $matches[2] I just don't know what the regex is somone else know it? This is an example of how the data is written out.

Code:
drwxrwxrwx   3 10300  0       512 Mar 18  2002 cronscripts
-rw-r--r--   1 10300  0         0 May  8  2002 index.html
drwxr-xr-x   7 65534  65534  2048 Dec 19 20:17 phpMyAdmin
drwxr-xr-x   3 10300  0      2048 Apr  2  2002 phpPgAdmin
drwxrwxrwx  13 10300  0       512 May 27  2002 weblogs


everything but index.html is a directory so as you see it starts all directories with d and all that is needed is to get the last word after the last space.
__________________
Miscellaneous Software
Viper_SB
Developershed E-Support


Anyone else play chess?
Challenge me

Reply With Quote
  #3  
Old May 21st, 2003, 02:02 AM
ikaros ikaros is offline
PHP Programmer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2000
Posts: 31 ikaros User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 36 m 43 sec
Reputation Power: 9
Send a message via ICQ to ikaros
i think you misunderstood me. i know perfectly well how the listing is done (even the recursive part). my problem is that it takes such a long time to get the list from the ftp server, and i was hoping you guys could give me som help optimizing it.

what i want to do is to list ALL directories and subdirectories belonging to the active user in a nice explorer-like directory tree. this i know how to do, but it is very time consuming.

Reply With Quote
  #4  
Old May 21st, 2003, 01:09 PM
Viper_SB's Avatar
Viper_SB Viper_SB is offline
Psycho Canadian
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Jan 2001
Location: Canada
Posts: 4,788 Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 4 Weeks 20 h 7 m 56 sec
Reputation Power: 437
ah ic your point sorry you want to see them all at once? I tried this once and found that it takes way to long to go though all directories, what about just showing there home dir with directories and then they click it and browse each dir like the old NC or MC?

Reply With Quote
  #5  
Old May 22nd, 2003, 01:57 AM
ikaros ikaros is offline
PHP Programmer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2000
Posts: 31 ikaros User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 36 m 43 sec
Reputation Power: 9
Send a message via ICQ to ikaros
yeah, that was version 1 but then my employer thought it would be nice to be able to see the whole directory tree in a separate frame.

if there's just a few files and directories it takes only 2 or 3 seconds to load the frame, but in some cases it takes well over one minute, and sometimes the script even times out. (raising the time out limit is not an option here, no one should wait more than 10 seconds for a page to be displayed)

Reply With Quote
  #6  
Old May 22nd, 2003, 11:37 AM
Viper_SB's Avatar
Viper_SB Viper_SB is offline
Psycho Canadian
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Jan 2001
Location: Canada
Posts: 4,788 Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Viper_SB User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 4 Weeks 20 h 7 m 56 sec
Reputation Power: 437
Yep I agree that is to long , I'm out of ideas besides telling your employer that if they want that feature then they'll have to sacirfice speed, maybe give the user the option to have either version displayed and see how many go for the speed instead of the features. Another thing if they user doesn't change the directory structure but only changes files keep the dir tree in an array or something then that is just pasted on each page and would only be slow the first time they accessed it or if they made changes to the structure.

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationFTP Help > listing ftp directories


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway