A word of caution, execution via FTP isn't very widely supported. Check that it works on the servers that you intend to connect to before you start coding something that requires this.
(PHP 4 >= 4.0.3, PHP 5, PHP 7, PHP 8)
ftp_exec — Exécute une commande sur un serveur FTP
$ftp
, string $command
): bool
ftp_exec() envoie une commande SITE EXEC
au serveur FTP, pour qu'il exécute le programme command
.
ftp
L'identifiant du lien de connexion FTP.
command
La commande à exécuter.
Retourne true
si la commande a été exécutée avec succès (le serveur
envoie le code réponse : 200
); sinon, retourne false
.
Exemple #1 Exemple avec ftp_exec()
<?php
// Initialisation de la variable
$command = 'ls -al >files.txt';
// Initialisation de la connexion
$conn_id = ftp_connect($ftp_server);
// Identification
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// Éxécution d'une commande
if (ftp_exec($conn_id, $command)) {
echo "$command a été exécuté avec succès\n";
} else {
echo "Impossible d\'exécuter : $command\n";
}
// Fermeture de la connexion
ftp_close($conn_id);
?>
A word of caution, execution via FTP isn't very widely supported. Check that it works on the servers that you intend to connect to before you start coding something that requires this.