I've write a couple of byte for an script to connect to a server through FTP and show the files contained into an a specified path :
// set up basic connection
$conn_id = ftp_connect($ip,$port,10);
// check connection
if (!$conn_id) {
$serverstatus='down';
} else {
$serverstatus='up';
}
// login with username and password
$login_result = ftp_login($conn_id,$usr,$pass);
// check login
if (!$login_result) {
$checklogin='ko';
} else {
$checklogin='ok';
}
if (@ftp_chdir($conn_id,$path)) {
$checkpath='ok';
// get contents of directory
$contents = ftp_rawlist($conn_id,"");
// assign value each entry
foreach ($contents as $entry) {
$list.=$entry."<br>\n";
}
// check files
if ($list == '') {
$checklist='ko';
} else {
$checklist='ok';
}
} else {
$checkpath='ko';
$checklist='ko';
}
}
echo $list;
If in the path are present only files it works fine , but if in the path are present a subfolder it show the subfolder name only.
How i can put into a $list variable a complete tree of specified $path ( subfolder and files contained in it ) ??
example : $list=
$path ------
|---- files1
|---- files2
|-----files3
|-----subfolder1
| |-------files1a
| |-------files2a
| |-------files3a
|-----files4
|-----files5
|-----subfolder2
| |-------files1b
| |-------files2b
| |-------files3b
.... another question , It's possible to put into a variable the FTP reply error code value if the connect / login failed ?
Such as 421,530 .etc.etc ??