<?php
require_once('defines.php');
require_once ('class.ftp.php');
echo "<b>FTP CLIENT EXAMPLE</b><br><br>";
echo 'developed by : <a href="mailto:my_sky_mc@yahoo.com">Marius Mischie </a> ©Sky Programming, 2008<br>';
echo "========================================================<br>";
$ftp= new FTPC($srv,$usr,$pass,$startf);
$ftp->connect();
if ($ftp->connected!=true) die("Could not connect!!");
echo "<font color='red'>...connected</font> @$ftp->server.<br>";
$ftp->login();
if ($ftp->logged_in!=true) die("Could not login!!");
echo "<font color='red'>...logged in as</font> $ftp->username<br>";
$ftp->set_curr_dir($startf);
echo "<font color='red'>...current directory : </font>";
echo $ftp->get_current_dir();
echo "<font color='red'><br>...download test result : </font>";
echo $ftp->download("testchmod.jpg","savefile.jpg");
echo "<br>";
//Upload example
//echo $ftp->upload("local.jpg","remote.jpg");
//echo "<br>";
// get the file list for curent directory
echo "========================================================<br>";
echo "DIRECTORY LISTING :<br><br>";
$contents = ftp_rawlist($ftp->connection, '/'.$startf);
$d_i=0;
$f_i=0;
$l_i=0;
$i=0;
while ($contents[$i]) {
$item[] = split("[ ]+",$contents[$i],9);
$item_type=substr($item[$i][0],0,1);
if ($item_type == "d") {
/* it's a directory */
$nlist_dirs[$d_i]=$item[$i][8];
$d_i++;
} elseif ($item_type == "l") {
/* it's a symlink */
$nlist_links[$l_i]=$item[$i][8];
$l_i++;
} elseif ($item_type == "-") {
/* it's a file */
$nlist_files[$f_i]=$item[$i][8];
$nlist_filesize[$f_i]=$item[$i][4];
$f_i++;
} elseif ($item_type == "+") {
/* it's something on an anonftp server */
$eplf=split(",",implode(" ",$item[$i]),5);
if ($eplf[2] == "r") {
/* it's a file */
$nlist_files[$f_i]=trim($eplf[4]);
$nlist_filesize[$f_i]=substr($eplf[3],1);
$f_i++;
} elseif ($eplf[2] == "/") {
/* it's a directory */
$nlist_dirs[$d_i]=trim($eplf[3]);
$d_i++;
}
} /* ignore all others */
$i++;
}
echo '<select name="select_directory" size="10" width="100">';
if($nlist_dirs[0]=="") $nlist_dirs[0]="No Dirs!";
for ($i=0; $i < count($nlist_dirs); $i++) {
echo "<option value=\"" . $nlist_dirs[$i] . "\">" . $nlist_dirs[$i] . "</option>\n";
}
echo '</select>';
echo '<select name="select_file" size="10">';
for ($i=0; $i < count($nlist_files); $i++) {
echo "<option value=\"" . $nlist_files[$i] . "\">" . $nlist_files[$i] ." ($nlist_filesize[$i] bytes)". "</option>\n";
}
echo '</select>';
?>
|