Send files via FTP with PHP

Asked

Viewed 2,094 times

4

I have the following PHP code to upload PHP files and send to an external server via FTP. However, it returns me the following error when I 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";

?>

1 answer

6


You can test enable passive mode on FTP:

ftp_pasv($conn_id, true);

Before starting the 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);
  • Ahhh man. Thank you very much. Solved my problem. kkk the arquivoi was like a bullet to another server.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.