222 lines
4.3 KiB
PHP
222 lines
4.3 KiB
PHP
|
<?php
|
||
|
|
||
|
/**-----------------------------------------------
|
||
|
*
|
||
|
* Rooty, 2018 <rooty@rooty.me>
|
||
|
*
|
||
|
*
|
||
|
* This software is protected by copyright, please
|
||
|
* read the file COPYRIGHT.
|
||
|
* This program is distributed in the hope that it
|
||
|
* will be useful, but without any warranty; without
|
||
|
* even the implied warranty of merchantability or
|
||
|
* fitness for a particular purpose. Please
|
||
|
* read the file LICENCE.
|
||
|
*
|
||
|
* Ce fichier contient la gestion de connections ftp...
|
||
|
*
|
||
|
* @author Rooty <www.rooty.me|rooty@rooty.me>
|
||
|
* @since 2005/03/09
|
||
|
* @link www.rooty.me
|
||
|
* @version 0.3
|
||
|
* @package package
|
||
|
* @subpackage ftp
|
||
|
* @copyright Copyright © 2009-2018, Rooty
|
||
|
*/
|
||
|
|
||
|
if ( !defined('SYSTEM_IN') )
|
||
|
{
|
||
|
die("Hacking attempt");
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Classe Ftp
|
||
|
*classe de gestion ftp.
|
||
|
* @package package
|
||
|
* @subpackage ftp
|
||
|
*/
|
||
|
class Ftp
|
||
|
{
|
||
|
|
||
|
/**#@+
|
||
|
* @access private
|
||
|
*/
|
||
|
/**
|
||
|
* @desc lien de ressources ftp
|
||
|
* @var entier
|
||
|
*/
|
||
|
var $id =null;
|
||
|
|
||
|
/**
|
||
|
* @desc login ftp
|
||
|
* @var entier
|
||
|
*/
|
||
|
var $login =null;
|
||
|
|
||
|
/**
|
||
|
* @desc passwd ftp
|
||
|
* @var entier
|
||
|
*/
|
||
|
var $passwd =null;
|
||
|
|
||
|
/**
|
||
|
* @desc serveur ftp
|
||
|
* @var entier
|
||
|
*/
|
||
|
var $server =null;
|
||
|
|
||
|
/**#@-*/
|
||
|
//
|
||
|
// Constructeur
|
||
|
//
|
||
|
|
||
|
/**
|
||
|
* Constructeur de la classe ftp en PHP4
|
||
|
* @param chaine serveur ftp
|
||
|
* @param chaine login ftp
|
||
|
* @param chaine passwd ftp
|
||
|
*/
|
||
|
function Ftp($server, $login, $passwd="")
|
||
|
{
|
||
|
$this->__construct($server, $login, $passwd);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Constructeur de la classe ftp en PHP5
|
||
|
* @param chaine serveur ftp
|
||
|
* @param chaine login ftp
|
||
|
* @param chaine passwd ftp
|
||
|
*/
|
||
|
function __construct($server, $login, $passwd="")
|
||
|
{
|
||
|
$this->server=$server;
|
||
|
$this->login=$login;
|
||
|
$this->passwd=$passwd;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Connection au ftp
|
||
|
*NB: la connection en ssl ne peut être éffectuée que si apache (module) le permet.
|
||
|
* @param booleen connection ssl?
|
||
|
* @return booleen
|
||
|
*/
|
||
|
function connect($ssl=false)
|
||
|
{
|
||
|
// $ftp_connid = ftp_connect($this->server);
|
||
|
if (checkdnsrr( $this->server, "ANY" )) {
|
||
|
if ($ssl==false)
|
||
|
{
|
||
|
|
||
|
if (ftp_connect($this->server))
|
||
|
{
|
||
|
$this->id=ftp_connect($this->server);
|
||
|
}
|
||
|
}else{
|
||
|
if (ftp_ssl_connect($this->server))
|
||
|
{
|
||
|
$this->id=ftp_ssl_connect($this->server);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if ($this->id===false || $this->id==null)
|
||
|
{
|
||
|
return false;
|
||
|
}else{
|
||
|
$login = ftp_login($this->id, $this->login, $this->passwd);
|
||
|
|
||
|
// Cas mauvais login/passwd
|
||
|
if ($login==null)
|
||
|
return false;
|
||
|
//
|
||
|
//Enable PASV ( Note: must be done after ftp_login() )
|
||
|
//
|
||
|
$mode = ftp_pasv($this->id, TRUE);
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
} else {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Connection au ftp
|
||
|
*NB: la connection en ssl ne peut être éffectuée que si apache (module) le permet.
|
||
|
* @param chaine chemin du repéretoire ftp.
|
||
|
* @return tableau tableau 0=>chemin&nom de fichier 1=>("Directory", "File") 2=>nom de fichier
|
||
|
*/
|
||
|
function getContentDir($path)
|
||
|
{
|
||
|
$tabResult=array();
|
||
|
// Récupération du contenu d'un dossier
|
||
|
$files = ftp_nlist($this->id, $path);
|
||
|
$i=0;
|
||
|
|
||
|
if ($files!==false)
|
||
|
{
|
||
|
foreach ($files as $file) {
|
||
|
$tabResult[$i][2]=$file;
|
||
|
$tabResult[$i][0]=$path.'/'.$file;
|
||
|
$isfile = ftp_size($this->id, $file);
|
||
|
if($isfile == "-1") { //Is a file or directory?
|
||
|
$tabResult[$i][1]="Directory";
|
||
|
}else{
|
||
|
$tabResult[$i][1]="File";
|
||
|
}
|
||
|
$i++;
|
||
|
}
|
||
|
}
|
||
|
return $tabResult;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Récupération d'un fichier via ftp
|
||
|
*NB: la connection en ssl ne peut être éffectuée que si apache (module) le permet.
|
||
|
* @param chaine fichier source (sur le serveur ftp)
|
||
|
* @param chaine fichier destination (sur le serveur local)
|
||
|
* @param entier droit du fichier
|
||
|
* @return tableau tableau
|
||
|
*/
|
||
|
function downLoadFile($fileSrc, $fileDest, $right=0775)
|
||
|
{
|
||
|
if (ftp_get($this->id, $fileDest, $fileSrc, FTP_BINARY)) {
|
||
|
@chmod($fileDest, $right);
|
||
|
return true;
|
||
|
} else {
|
||
|
@unlink($fileDest);
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Récupération de la taille d'un fichier
|
||
|
*
|
||
|
* @param chaine fichier source (sur le serveur ftp)
|
||
|
* @param chaine fichier destination (sur le serveur local)
|
||
|
* @param entier droit du fichier
|
||
|
* @return tableau tableau
|
||
|
*/
|
||
|
function getSize($file){
|
||
|
// Récupération de la taille du fichier $file
|
||
|
$res = ftp_size($this->id, $file);
|
||
|
if ($res != -1) {
|
||
|
return $res;
|
||
|
} else {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Fermeture de la connection ftp
|
||
|
* @return booleen
|
||
|
*/
|
||
|
function close()
|
||
|
{
|
||
|
$bool=ftp_close($this->id);
|
||
|
if($bool)
|
||
|
$this->id=null;
|
||
|
return $bool;
|
||
|
}
|
||
|
}
|
||
|
?>
|