Ver Mensaje Individual
  #1 (permalink)  
Antiguo 30/05/2012, 04:26
OMG_RZ
 
Fecha de Ingreso: mayo-2012
Mensajes: 1
Antigüedad: 11 años, 10 meses
Puntos: 0
Exclamación Problemas al descargar fichero de entro de una carpeta

Buenas, soy nuevo por aqui y queria exponeros un problemilla que tengo.

Estoy intentando descargar archivos que estan dentro de una subcarpeta. Los archivos que estan en el raiz se descargan completamente pero los archivos que están dentro de una carpeta no me los coge ni tampoco las carpetas.

Os adjunto el script que extraí de una pagina y le modifique.

<?php
# Linear connection info for connecting to FTP

# set up basic connection
$ftp_server = "";
$ftp_user = "";
$ftp_pass = "";

$ftp_conn = ftp_connect($ftp_server);
$ftp_login = ftp_login($ftp_conn, $ftp_user, $ftp_pass);

ftp_pasv($ftp_conn, true);

# check connection
if ((!$ftp_conn) || (!$ftp_login)) {
echo "FTP connection has failed!<br>";
echo "Attempted to connect to $ftp_server for user $ftp_user";
} else {
echo "Connected to $ftp_server, for user $ftp_user <br>";
}

echo "Currently in ".ftp_pwd($ftp_conn);

if (ftp_chdir($ftp_conn, "carpeta_origen")) {
echo "Current directory is now: " . ftp_pwd($ftp_conn) . "\n <br>";
} else {
echo "Couldn't change directory\n<br>";
}

# Dump the data to the screen
var_dump(ftp_rawlist($ftp_conn, '.'));
# For the actual ftp actions, I use a FTP class I wrote which you can grab below
FTP::download(APPPATH.'carpeta_destino', '.', $ftp_conn);

ftp_close($ftp_conn);
?>

<?php
# FTP Class for performing file downloads
class FTP {

/**
* Download() performs an automatic syncing of files and folders from a remote location
* preserving folder and file names and structure
*
* @param $local_dir: The directory to put the files, must be in app path and be writeable
* @param $remote_dir: The directory to start traversing from. Use "." for root dir
*
* @return null
*/
public static function download($local_dir, $remote_dir, $ftp_conn)
{

if ($remote_dir != ".") {
if (ftp_chdir($ftp_conn, $remote_dir) == false) {
echo ("Change Dir Failed: $remote_dir<br />\r\n");
return;
}
if (!(is_dir($remote_dir)))
mkdir($remote_dir);
chdir ($remote_dir);
}

$contents = ftp_nlist($ftp_conn, ".");
foreach ($contents as $file) {

if ($file == '.' || $file == '..')
continue;

if (@ftp_chdir($ftp_conn, $file)) {
ftp_chdir ($ftp_conn, "..");
FTP::download($local_dir, $file, $ftp_conn);
}
else
ftp_get($ftp_conn, "$local_dir/$file", $file, FTP_BINARY);
}

ftp_chdir ($ftp_conn, "..");
chdir ("..");
}

}
?>