FTP list folders

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
user___
Forum Contributor
Posts: 297
Joined: Tue Dec 05, 2006 3:05 pm

FTP list folders

Post by user___ »

Hi guys,
I have been trying to display all folders on a remote FTP server but I could not find a solution. I tried the raw list function but the problem comes from the fact that it reads only files and as soon as I created a folder my script got stuck. Do you have any ideas of how to do that because I could not find an exact function for that task.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Post your code.
user___
Forum Contributor
Posts: 297
Joined: Tue Dec 05, 2006 3:05 pm

Reply

Post by user___ »

Thank you for the fast reply, feyd. The test code I have (Actually I have a class which has a function whose fubctionality is sinilkar to that sample) is a sample from http://www.php.net. It is used to print files and folders on the remote host but when there is a direcory it gets stuck.
This is the code:

Code: Select all

<?php

// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// get the file list for /
$buff = ftp_rawlist($conn_id, '/');

// close the connection
ftp_close($conn_id);

// output the buffer
var_dump($buff);
?>
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

ftp_nlist() example in the manual page shows the function returning folder names.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply