note 73401 deleted from function.ftp-nlist by sobak
| From: | sobak@php.net | Date: | Thu, 01 Dec 2016 12:55:48 +0000 |
| Subject: | note 73401 deleted from function.ftp-nlist by sobak | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-207840@lists.php.net to get a copy of this message | ||
Note Submitter: josh at servebyte dot com
----
Function Keywords: is_file is_dir
<?php
$ftp_server = 'IP OR HOSTNAME HERE';
$ftp_user_name = 'USERNAME';
$ftp_user_pass = 'PASSWORD';
// 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);
function ftp_is_dir($folder) {
global $conn_id;
if (ftp_chdir($conn_id, $folder)) {
ftp_chdir($conn_id, '..');
return true;
} else {
return false;
}
}
function xdir($path) {
global $conn_id;
$contents = ftp_nlist($conn_id, $path);
foreach($contents as $file) {
if ($file!='.'&&$file!='..') {
if (ftp_is_dir($file)) {
echo $file . ' is a folder<br>';
} else {
echo $file . ' is a file<br>';
}
}
}
}
xdir('.');
?>
can be looped through... using the function xdir if the file is a folder ;)
Returns a warning upon not being a folder... use error_reporting(0); to resolve this issue.