All pastes #806184 Raw Edit

XwZ

public php v1 · immutable
·published 2007-12-05 00:33 UTC
rendered paste body
<?php	/*********************************************************************************************************************************	**	**		Classe FTP	**	**		Cree par XwZ	**		E-mail : webmaster[@]htmlearn.net	**		Cree le : 15-08-2007	**		Derniere mise a jour : 16-08-2007	**	**		La classe contient :	**			- Les constructeurs et destructeurs :	**				__construct ( entree $host <string>, entree $user <string>, entree $pass <string>, entree $port <integer> )	**					Initialise les valeurs utilisees pour se connecter au serveur	**	**				__destruct ( void )	**					Ferme la connexion au serveur ftp	**	**			- Les fonctions de bases :	**				connexion ( )	**					Creer une connexion au serveur ftp, et renvois :	**					- 1 si la connexion au serveur a echoue	**					- 2 si l'identification a echoue	**					- 3 si tout est ok	**	**				pwd	**					retourne le chemin du repertoire courant 	**	**				ls	**					retourne un tableau avec la liste des fichiers presents dans le dossier courant 	**	**				upload ( entree fichier_distant <string>, entree fichier_local <string>, entree mode <string> )	**					Upload le _fichier_local_ dans le repertoire courant sous le nom _fichier_distant_ avec le _mode_ choisi,	**					_mode_ ne peut avoir que ces deux valeur : FTP_ASCII et FTP_BINARY	**	**				download ( entree fichier_local <string>, entree fichier_distant <string>, entree mode <constante> )	**					Download le _fichier_distant_ dans le repertoir courant sous le nom _fichier_local_ avec le _mode_ choisi	**					_mode_ ne peut avoir que ces deux valeur : FTP_ASCII et FTP_BINARY	**	**				chmod ( entree fichier <string>, entree mode <string> )	**					Change les droits d'acces du _fichier_ pour les droits indique dans _mode_	**	**				mkdir ( entree dossier <string> )	**					Cree un repertoire dans le repertoire courant sous le nom de _dossier_	**	**				rm ( entree fichier <string> )	**					Supprime le _fichier_ du repertoire courant	**	**				rmdir ( entree dossier <string> )	**					Supprime le _dossier_ du repertoire courant	**	**				set_mode ( entree mode <constante> )	**					Definit le mode de transmission par defaut	**					_mode_ ne peut avoir que ces deux valeur : FTP_ASCII et FTP_BINARY	**	*********************************************************************************************************************************/	class ftp {		private $host ;		private $user ;		private $pass ;		private $port ;		private $flux_connexion ;		private $flux_identification ;		private $mode_transmission ;		public function __construct ( $host, $user, $pass, $port = 21 ) {			$this -> host = $host ;			$this -> user = $user ;			$this -> pass = $pass ;			$this -> port = $port ;		}		public function __destruct ( ) {			if ( !$this -> flux_connexion === false && $this -> flux_identification === true  ) {				ftp_close ( $this -> flux_connexion ) ;			}		}		public function connexion () {			$this -> flux_connexion = ftp_connect ( $this -> host, $this -> port ) ; // or die ( "erreur de connexion" ) ;			if ( !$this -> flux_connexion === true ) {				return 1 ;			}			else {				$this -> flux_identification = ftp_login ( $this -> flux_connexion, $this -> user, $this -> pass ) ;				if ( !$this -> flux_identification === true ) {					return 2 ;				}				else {					return 3 ;				}			}		}		public function pwd () {			if ( !$this -> flux_connexion === false && $this -> flux_identification === true ) {				return ftp_pwd ( $this -> flux_connexion ) ;			}			else {				return false ;			}		}		public function cd ( $repertoire ) {			if ( !$this -> flux_connexion === false && $this -> flux_identification === true  ) {				return ftp_chdir ( $this -> flux_connexion, $repertoire ) ;			}			else {				return false ;			}		}		public function ls ( $dossier = '.' ) {			if ( !$this -> flux_connexion === false && $this -> flux_identification === true  ) {				$sortie = array ( ) ;				$i = 0 ;				$tab_ls = ftp_nlist ( $this -> flux_connexion, $dossier ) ;				if ( $tab_ls !== FALSE ) {					foreach ( $tab_ls AS $id => $fichier ) {						if ( $fichier != '.' AND $fichier != '..' ) {							$sortie [ $i ] = $fichier ;							$i++;						}					}					return $sortie ;				} else {					return false ;				}			} else {				return false ;			}		}		public function upload ( $fichier_distant, $fichier_local, $mode = '' ) {			if ( true === empty ( $mode ) ) {				$mode = $this -> mode_transmission ;			}			if ( !$this -> flux_connexion === false && $this -> flux_identification === true  ) {				return ftp_put ( $this -> flux_connexion, $fichier_distant, $fichier_local, $mode ) ;			}			else {				return false ;			}		}		public function download ( $fichier_local, $fichier_distant, $mode = '' ) {			if ( true === empty ( $mode ) ) {				$mode = $this -> mode_transmission ;			}			if ( !$this -> flux_connexion === false && $this -> flux_identification === true  ) {				return ftp_get ( $this -> flux_connexion, $fichier_local, $fichier_distant, $mode ) ;			}			else {				return false ;			}		}		public function chmod ( $fichier, $mode ) {			if ( !$this -> flux_connexion === false && $this -> flux_identification === true  ) {				return ftp_chmod ( $this -> flux_connexion, $mode, $fichier ) ;			}			else {				return false ;			}		}		public function mkdir ( $dossier ) {			if ( !$this -> flux_connexion === false && $this -> flux_identification === true  ) {				return ftp_mkdir ( $this -> flux_connexion, $dossier ) ;			}			else {				return false ;			}		}		public function rm ( $fichier ) {			if ( !$this -> flux_connexion === false && $this -> flux_identification === true  ) {				return ftp_delete ( $this -> flux_connexion, $fichier ) ;			}			else {				return false ;			}		}		public function rmdir ( $repertoire ) {			if ( !$this -> flux_connexion === false && $this -> flux_identification === true  ) {				return ftp_rmdir ( $this -> flux_connexion, $repertoire ) ;			}			else {				return false ;			}		}		public function set_mode ( $mode ) {			$this -> mode_transmission = $mode ;		}	} ;?>