Send files via FTP with PHP

4

I have the following code in PHP for UPLOAD of files in PHP and send to an external server via FTP. However, it returns the following error when I do UPLOAD:

Warning: ftp_put(): Illegal PORT command. in /var/www/protocolo/teste/envia.php on line 26

What can it be?

<?php
ini_set("default_charset", "UTF-8");
$ftp_server = "meuhostftp.com.br";
$ftp_username   = "root";
$ftp_password   =  "root";


$conn_id = ftp_connect($ftp_server) or die("could not connect to $ftp_server");

// login
if (@ftp_login($conn_id, $ftp_username, $ftp_password))
{
  echo "Conectado a $ftp_username@$ftp_server\n";
}
else
{
  echo "Não foi possível conectar com $ftp_username\n";
}

$file = $_FILES["uploadedfile"]["name"];

$remote_file_path = "/var/www/html/teste/".$file;

ftp_put($conn_id, $remote_file_path, $_FILES["uploadedfile"]["tmp_name"], FTP_BINARY);

ftp_close($conn_id);

echo "\n\nConexão encerrada";

?>
    
asked by anonymous 05.06.2017 / 16:52

1 answer

5

You can try enabling passive mode in FTP:

ftp_pasv($conn_id, true);

Before you begin ftp_put :

ftp_pasv($conn_id, true); // habilitar o modo passivo do FTP...
ftp_put($conn_id, $remote_file_path, $_FILES["uploadedfile"]["tmp_name"], FTP_BINARY);
    
05.06.2017 / 16:59