J'ai plusieurs recherches mais je n'ai rien trouvé de concret jusqu'à présent. pouvez vous au moins me dire si c'est réalisable en PHP:
JE souhaites transferer un répertoire entier d'un ftp à un autre.
Le script en question ne pouvant étre mis sur le serveur source.
donc soit copie de FTP à FTP à partir d'un serveur distant.
soit FTP à local avec le script en local.
MErci
Redox
Modérateurs
Inscrit le: 07 Sep 2004
Messages: 973
Posté le: Lun 01 Mai 2006, 2:21 pm
Salut,
Oui c'est réalisable en PHP et expliqué dans la doc où il y avait un script tout fait pour cela:
Code:
<?php
//If you want to move or replicate the folder hierarchy from your current server to another remote server. Then this will be helpful as this will browse the current server's directory and at the same time it will copy that file in the remote server in the same directory.
//This script will copy all the files from this directory and subdirectory to another remote server via FTP
if (is_dir($source_path))
{
chdir($source_path);
$handle=opendir('.');
while (($file = readdir($handle))!==false)
{
if (($file != ".") && ($file != ".."))
{
if (is_dir($file))
{
// here i am restricting the folder name 'propertyimages' from being copied to remote server. -- VK
if($file != "propertyimages")
{
rec_copy ($source_path."/".$file, $file, $con);
chdir($source_path);
ftp_cdup($con);
}
}
if (is_file($file))
{
$fp = fopen($file,"r");
// this will convert spaces to '_' so that it will not throw error. -- VK
ftp_fput ($con, str_replace(" ", "_", $file), $fp,FTP_BINARY);
ftp_site($con, 'CHMOD 0755 '.str_replace(" ", "_", $file));
}
}
}
closedir($handle);
}
}
// make a FTP connection --VK
$con = ftp_connect("69.18.213.131",21);
$login_result = ftp_login($con,"username","password");
// this is the root path for the remote server-- VK
$rootpath = "mainwebsite_html";
// this is the physical path of the source directory. actually u can also use the relative path. -- VK
$sourcepath = realpath("../")."/resdesk";
// this directory name will only change the top most directory and not the inner one -- VK
$destination_dir_name = "resdesk_".$account_id."/";
rec_copy ($sourcepath, $destination_dir_name, $con);
if (function_exists("ftp_close"))
{
ftp_close($con);
}
?>
merci pour cette réponse, peut étre un élément de réponse dans ton lien.
ton scritp c'est pour du local vers FTP on dirait non?
Redox
Modérateurs
Inscrit le: 07 Sep 2004
Messages: 973
Posté le: Lun 01 Mai 2006, 4:05 pm
merci pour cette réponse, peut étre un élément de réponse dans ton lien.
ton scritp c'est pour du local vers FTP on dirait non?
La réponse est le script lui même !
Et il marche pour serveur à serveur (et peut être de local a serveur, à tester), je cite:
move or replicate the folder hierarchy from your current server to another remote server
tnerual
Inscrit le: 01 Mai 2006
Messages: 7
Posté le: Lun 01 Mai 2006, 6:11 pm
bin oui il fonctionne de local a serveur, et c'est justment ce que je ne veut pas ou du moins l'inverse.
le script en question doit aller chercher des repertoires (sur un FTP lambda que je rentrerai par formulaire) pour les mettre sur mon espace web à moi (ou sur un autre FTP).
v mettre le script à "l'envers", chuis tellement doué que ca risque de pas marcher.
tnerual
Inscrit le: 01 Mai 2006
Messages: 7
Posté le: Lun 01 Mai 2006, 10:26 pm
j'y arrive po
sur le lien que tu as donner c'est ca qu'il me faudrait mais le lien est mort:
Here is an example for downloading a remote ftp structure to local server, useful for migrating sites from one server to another, especially when you are upgrading ensim
if ($action == "copy") {
// Connect to source ftp server
$status = ftp_connect($host,21);
if (!$status) { die ("<center><h1>FTP CONNECTION FAILED TO $host</h1></center>"); }
$login = ftp_login ($status,$username,$pswd);
if (!$login) { die ("<center><h2>Username or Password not accepted on host $host</h2></center>"); }
$dirlist = ftp_nlist ($status,$dir);
if (!$dirlist) { die ("<center><h3>Cannot read directory $dir on host $host</h3></center>"); }
<p align=\"center\"><br>
<br>
<b>Note :</b> If ftp connection failed, try using <a href=\"ftp://ftp.yourdomain.com\">ftp.yourdomain.com</a>
or <a href=\"http://www.yourdomain.com\">www.yourdomain.com</a> <br>
eliminate the "<a href=\"ftp://\">ftp:// </a>" protocol<br>
<br>
</p>
</body>
</html>";
}
?>
Dernière édition par tnerual le Ven 05 Mai 2006, 3:53 pm; édité 1 fois
tnerual
Inscrit le: 01 Mai 2006
Messages: 7
Posté le: Mar 02 Mai 2006, 3:41 am
Une autre question
ce scipt s'execute trés bien sur mon serveur chez ovh mais le méme en local chez moi avec apache il se passe rien. j'ai oublier de config un truc dans apache???
Redox
Modérateurs
Inscrit le: 07 Sep 2004
Messages: 973
Posté le: Mar 02 Mai 2006, 7:14 pm
Y a-t-il des erreurs qui sont générées qui pourraient nous mettre sur la voie...
tnerual
Inscrit le: 01 Mai 2006
Messages: 7
Posté le: Mar 02 Mai 2006, 7:21 pm
Bin en fait non justement, il se passe strictement rien, je rempli le formulaire et des que je valide je suis toujours sur le formulaire qui est redevenu vierge comme si la page s'actualisait.
y a t'il des options a rajouter dans mon php.ini pour certaines fonctions phph soit valides?
Vous pouvez poster de nouveaux sujets dans ce forum Vous pouvez répondre aux sujets dans ce forum Vous ne pouvez pas éditer vos messages dans ce forum Vous ne pouvez pas supprimer vos messages dans ce forum Vous ne pouvez pas voter dans les sondages de ce forum
Toutes les heures sont au format GMT + 2 Heures
Page 1 sur 1