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 — Fordert die Ausführung eines Programmes auf dem FTP-Server an
$ftp
, string $command
) : bool
Sendet ein SITE EXEC-Kommando (command
) an den
FTP-Server.
ftp
Die Verbindungskennung der FTP-Verbindung.
command
Das auszuführende Kommando.
Gibt true
zurück, wenn das Kommando erfolgreich war (d. h. der Server hat
den Antwortcode 200
geliefert); sonst false
.
Beispiel #1 ftp_exec()-Beispiel
<?php
// Variable initialisieren
$command = 'ls -al >files.txt';
// Verbindung aufbauen
$conn_id = ftp_connect($ftp_server);
// Login mit Benutzername und Passwort
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// Kommando ausführen
if (ftp_exec($conn_id, $command)) {
echo "$command wurde erfolgreich ausgeführt\n";
} else {
echo "$command konnte nicht ausgeführt werden\n";
}
// Verbindung schließen
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.