Pravin Pravin - 1 year ago 96
PHP Question

PHP ftp_put fails

I upload XML file through FTP:

$ftp = "ftp";
$username = "username";
$pwd = "password";
$filename = $_FILES[$xyz][$abc];
$tmp = $_FILES['file']['tmp_name'];
$destination = "/Content/EnquiryXML ";

$connect = ftp_connect($ftp)or die("Unable to connect to host");
ftp_login($connect,$username,$pwd)or die("Authorization Failed");
echo "Connected!<br/>";

echo"Please select a file";

ftp_put($connect,$destination.'/'.$filename,$tmp,FTP_ASCII)or die("Unable to upload");
echo"File successfully uploaded to FTP";

I want to send the XML file created using
to a FTP server but I am not able.

returns false.

Answer Source

Most typical cause of problems with ftp_put is that PHP defaults to the active mode. And in 99% cases, one has to switch to the passive mode, to make the transfer working. Use the ftp_pasv function.

$connect = ftp_connect($ftp) or die("Unable to connect to host");
ftp_login($connect, $username, $pwd) or die("Authorization Failed");
// turn passive mode on
ftp_pasv($connect, true);

See also: