Viewing file: ftp_mueve_libros_viejos.php (7.26 KB) -rw-rw-r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
echo " ejecutar solo desde consola";
include "/home/wwwroot/frames/conn.php";
$sql="SELECT * FROM papyr225_papyre.libros
WHERE libros.inftp<>1 and libros.inftp<>3 order by id desc ";
$res=mysql_query($sql,$conn);
echo mysql_error();
while ($row=mysql_fetch_array($res)){
// sacamos los datos t los procesamos por separado. Promero, el fichero fb2
//ruta ruta_epub ruta_mobi
//http://papyrefb2.net/libros/16-257.zip
//http://papyrefb2.net/epub/17-338.epub
//http://papyrefb2.net/mobi/17-338.mobi
echo "RUTAS ACTUALES:".chr(10);
echo $row['ruta'].chr(10).$row['ruta_epub'].chr(10).$row['ruta_mobi'].chr(10);
@ob_flush();
@flush();
@ob_end_flush();
$array_libro=explode("/",$row['ruta']);
$elementos=count($array_libro);
$ruta="/home/wwwroot/".$array_libro[$elementos-2]."/".$array_libro[$elementos-1];
$nombre_fichero=$array_libro[$elementos-1];
echo "libro: {$row['id']} ruta fb2:$ruta".chr(10);
if (file_exists($ruta)){
ftp($ruta,"fb2",$nombre_fichero);
if (unlink ($ruta)){
echo " fichero $nombre_fichero borrado".chr(10);
}
mysql_query("update papyr225_papyre.libros set ruta='http://fichfilkraft.com/5652164542316554/fb2/$nombre_fichero', inftp=3 where id={$row['id']}",$conn);
echo mysql_error().chr(10);
}
if ($row['ruta_epub']){
$array_libro=explode("/",$row['ruta_epub']);
$elementos=count($array_libro);
$ruta="/home/wwwroot/".$array_libro[$elementos-2]."/".$array_libro[$elementos-1];
$nombre_fichero=$array_libro[$elementos-1];
echo "libro: {$row['id']} ruta epub:$ruta".chr(10);
if (file_exists($ruta)){
ftp($ruta,"epub",$nombre_fichero);
if (unlink ($ruta)){
echo " fichero $nombre_fichero borrado".chr(10);
}
mysql_query("update papyr225_papyre.libros set ruta_epub='http://fichfilkraft.com/5652164542316554/epub/$nombre_fichero', inftp=3 where id={$row['id']}",$conn);
echo mysql_error().chr(10);
}
}
if ($row['ruta_mobi']){
$array_libro=explode("/",$row['ruta_mobi']);
$elementos=count($array_libro);
$ruta="/home/wwwroot/".$array_libro[$elementos-2]."/".$array_libro[$elementos-1];
$nombre_fichero=$array_libro[$elementos-1];
echo "libro: {$row['id']} ruta mobi:$ruta".chr(10);
if (file_exists($ruta)){
ftp($ruta,"mobi",$nombre_fichero);
if (unlink ($ruta)){
echo " fichero $nombre_fichero borrado".chr(10);
}
mysql_query("update papyr225_papyre.libros set ruta_mobi='http://fichfilkraft.com/5652164542316554/mobi/$nombre_fichero',inftp=3 where id={$row['id']}",$conn);
echo mysql_error().chr(10);
}
}
/*
$array_libro=explode("/",$row['ruta_epub']);
$elementos=count($array_libro);
$ruta="/home/wwwroot/".$array_libro[$elementos-2]."/".$array_libro[$elementos-1];
$nombre_fichero=$array_libro[$elementos-1];
echo "libro epub: {$row['id']} ruta epub:$ruta".chr(10);
ftp($ruta,"epub",$nombre_fichero);
$array_libro=explode("/",$row['ruta_mobi']);
$elementos=count($array_libro);
$ruta="/home/wwwroot/".$array_libro[$elementos-2]."/".$array_libro[$elementos-1];
$nombre_fichero=$array_libro[$elementos-1];
echo "libro: {$row['id']} ruta mobi:$ruta".chr(10);
ftp($ruta,"mobi",$nombre_fichero);
*/
}
function ftp ($file,$tipo,$nombre_fichero)
{
$ftp_server = "ftp.fichfilkraft.com"; // add server name
//$ftp_user_name = "[email protected]"; // add user name
//$ftp_user_pass = "15xj3Gm5Fo"; // add password
$ftp_user_name = "[email protected]"; // add user name
$ftp_user_pass = "librosviejos"; // add password
$dst_dir = "/5652164542316554/$tipo"; // add destination directory ( www/upload/ )
$archivo_origen=$file;
$ftp= new ftp($ftp_server,$ftp_user_name,$ftp_user_pass,$dst_dir);
$ftp->delete($dst_dir."/".$nombre_fichero);
echo "<pre>";
echo "subiendo $archivo_origen";
$ftp->error=false;
$ftp->sendfile($nombre_fichero,$archivo_origen);
echo "<br>--------------------------fin----------------------<br>";
print_r($ftp);
if ($ftp->error)die();
$ftp->disconnect();
}
class ftp
{
public $ftp_server;
public $ftp_user_name;
public $ftp_user_pass;
public $dst_dir;
public $conn_id;
public $login_result;
public $mi_error;
public $error=false;
public $listadirectorio;
function ftp($ftp_server,$ftp_user_name,$ftp_user_pass,$dst_dir)
{
if ($ftp_server!="" && $ftp_user_name!="" && $ftp_user_pass!="" && $dst_dir!="") {
$this->ftp_server = $ftp_server;
$this->ftp_user_name = $ftp_user_name;
$this->ftp_user_pass = $ftp_user_pass;
$this->dst_dir = $dst_dir;
}
else
return false; // bad parametrs
if (!$this->connect()){
echo "bad connect";
return false;
}
if (!$this->setdir()){
echo "no exist directory ";
return false;
}
return true; // ALL OK
}
/* FTP connect */
function connect()
{
$this->conn_id = ftp_connect($this->ftp_server);
$this->login_result = ftp_login($this->conn_id, $this->ftp_user_name, $this->ftp_user_pass);
if ((!$this->conn_id) || (!$this->login_result))
return false;
else return true;
}
function disconnect()
{
return(ftp_close($this->conn_id));
}
/* Set Directory */
function setdir()
{
if (!ftp_chdir($this->conn_id, $this->dst_dir)){
$this->mi_error="no se pudo cambiar el directorio";
$this->error=true;
return false;
}else{
// echo ftp_pwd($this->conn_id);
return true;
}
}
/* Send file */
/*
INPUT:
$remote_file -> file for send
$file -> read file
$mode -> "FTP_BINARY","FTP_ASCII",...
*/
function sendfile($remote_file, $file, $mode="FTP_BINARY")
{
if (!ftp_put($this->conn_id, $remote_file, $file, FTP_BINARY)){
$this->mi_error="no se pudo subir {$remote_file} {$file}";
$this->error=true;
return false;
}else{ return true;
}
}
function getfile($local_file,$remote_file,$mode="FTP_BINARY")
{
$this->error=false;
if (!ftp_get($this->conn_id, $local_file, $remote_file, FTP_BINARY)){
$this->mi_error="no se pudo bajar {$remote_file} {$file}";
$this->error=true;
return false;
}else{
$this->error=false;
return true;
}
}
function delete($file)
{
if (!@ftp_delete($this->conn_id, $file)) {
$this->mi_error="no se pudo borrar {$file} en servidor remoto";
$this->error=true;
return false;
}else{ return true;
}
}
function ls()
{
$this->listadirectorio=ftp_nlist($this->conn_id, ftp_pwd($this->conn_id));
}
function rename($oldname, $newname)
{
if (!ftp_rename($this->conn_id, $oldname, $newname) ){
$this->mi_error="no se pudo cambiar el nombre {$oldname} al nuevo: {$newname}";
$this->error=true;
return false;
}else{ return true;
}
}
} //end class
?>
?>
?>
|