My FTP-Server always responded "bool(false)" instead of presenting me a directory-listing. I had to add
ftp_pasv($conn_id, true); right after the $login_result = ftp_login(...); line.
After that it just worked fine.
Exemplo #1 Exemplo da extensão FTP
<?php
// configura uma conexão básica
$ftp = ftp_connect($ftp_server);
// faz login com usuário e senha
$login_result = ftp_login($ftp, $ftp_user_name, $ftp_user_pass);
// verifica conexão
if ((!$ftp) || (!$login_result)) {
echo "Conexão FTP falhou!";
echo "Tentativa de conexão a $ftp_server para o usuário $ftp_user_name";
exit;
} else {
echo "Conectado a $ftp_server, para o usuário $ftp_user_name";
}
// envia o arquivo
$upload = ftp_put($ftp, $destination_file, $source_file, FTP_BINARY);
// verifica estado do envio
if (!$upload) {
echo "Envio por FTP falhou!";
} else {
echo "Enviado $source_file a $ftp_server como $destination_file";
}
// fecha a conexão FTP
ftp_close($ftp);
?>
My FTP-Server always responded "bool(false)" instead of presenting me a directory-listing. I had to add
ftp_pasv($conn_id, true); right after the $login_result = ftp_login(...); line.
After that it just worked fine.
I used following code successfully to connect to "lftp" server and see the complete dir listing.
also ftp_pasv($conn_id, true); trick works fine for lftp server :)
<?php
// set up basic connection
$ftp_server = "example.com";
$conn_id = ftp_ssl_connect($ftp_server);
// login with username and password
$ftp_user_name = "myuser";
$ftp_user_pass = "mypass";
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
ftp_pasv($conn_id, true);
// check connection
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name";
}
$buff = ftp_rawlist($conn_id, '.');
var_dump($buff);
ftp_close($conn_id);
?>
Thanks ,
Prajakta