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 — Solicita a execução de um comando no servidor FTP
$ftp_stream
, string $command
): bool
Envia uma solicitação SITE EXEC command
para o
servidor FTP.
ftp_stream
O identificador da conexão FTP.
command
O comando a executar.
Retorna true
se o comando for bem sucedido (o servidor enviou o código de resposta:
200
); se não retorna false
.
Exemplo #1 Exemplo ftp_exec()
<?php
// variable initialization
$command = 'ls -al >files.txt';
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// execute command
if (ftp_exec($conn_id, $command)) {
echo "$command executed successfully\n";
} else {
echo "could not execute $command\n";
}
// close the connection
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.