Transfert FTP

  Information

Transfert des fichiers entre les répertoires sur un serveur FTP
$destination : valeur "tolocal" ou "tohost"
$resultat est un tableau
$resultat[1] :fichier local a transférer sur l'hote
$resultat[-1] :fichier hote a transférer en local
  code source classé dans  FTP

 
 01    
 02    
 03    
 04    
 05    
 06    
 07    
 08    
 09    
 10    
 11    
 12    
 13    
 14    
 15    
 16    
 17    
 18    
 19    
 20    
 21    
 22    
 23    
 24    
 25    
 26    
 27    
 28    
 29    
 30    
 31    
 32    
 33    
 34    
 35    
 36    
 37    
 38    
 39    
 40    
 41    
 42    
 43    
 44    
 45    
 46    
 47    
 48    
 49    
 50    
 51    
 52    
 53    
 54    
 55    
 56    
 57    
 58    
 59    
 60    
 61    
 62    
 63    
 64    
 65    
                               
<?php
/*---------------------------------------------------------------*/
/*
    Titre : Transfert FTP                                                                                                 
                                                                                                                          
    URL   : https://phpsources.net/code_s.php?id=863
    Date édition     : 14 Fév 2019                                                                                        
*/
/*---------------------------------------------------------------*/

function transfert($server $user $pass $remote $local $destination 
$resultat){ 
 $last=substr($remote, -1); 
  $last2=substr($local, -1); 
  if ($last !="/") {$remote=$remote."/";} 
  if ($last !="/") {$local=$local."/";} 
  
  $ftpc=ftp_connect($server); 
  $result_login=ftp_login($ftpc$user$pass); 
  if ((!$result_login) || (!$ftpc)){ 
  return "impossible de se connecter"
  die
  } 
  
  switch($destination) { 
  case "tohost" 
  $retour=""
  $fichiersarray_values($resultat[1]); 
  foreach($fichiers as $nb) { 
  $local_dest=$remote.$nb
  $putftp_put($ftpc$local_dest$local.$nbFTP_BINARY); 
  if (!$put) { 
  $retour.= "Le telechargement de $nb a echoue \n"
  } 
  else { 
  $retour.= "telechargement de $nb vers $remote reussi \n"
  } 
  } 
  return $retour
  break; 
  
  
  case "tolocal" 
  $retour=""
  $fichiersarray_values($resultat[-1]); 
  foreach($fichiers as $nb) { 
  $remote_dest=$local.$nb
  $putftp_put($ftpc$remote_dest$remote.$nbFTP_BINARY); 
  if (!$put) { 
  $retour .= "Le telechargement de $nb a echoue \n"
  } 
  else { 
  $retour .= "telechargement de $nb vers $local reussi \n"
  } 
  } 
  return $retour
  break; 
  
  } 
  ftp_quit($ftpc); 
}

?>

          Fonctions du code - Doc officielle PHP

   php.net   Description Versions PHP OUTIL
   array_values Retourne les valeurs d'un tableau PHP 4, PHP 5, PHP 7, PHP 8
   die Alias de la fonction exit() PHP 4, PHP 5, PHP 7, PHP 8
   ftp_connect Ouvre une connexion FTP PHP 4, PHP 5, PHP 7, PHP 8
   ftp_login Identification sur un serveur FTP PHP 4, PHP 5, PHP 7, PHP 8
   ftp_put Charge un fichier sur un serveur FTP PHP 4, PHP 5, PHP 7, PHP 8
   ftp_quit Alias de ftp_close() PHP 4, PHP 5, PHP 7, PHP 8
   return Retourne le controle du programme au module appelant. PHP 4, PHP 5, PHP 7, PHP 8
   substr Retourne un segment de chaîne PHP 4, PHP 5, PHP 7, PHP 8

   Dites merci aux auteurs pour leurs travail, ça ne coûte rien et ça fait toujours plaisir wink

Présentation de PHP

PHP débutant et initié 50 Tutoriel

Présentation de MySQL