PHP ftp_put does not work with "Warning: ftp_put (): PORT command completed successfully"

The file is created on the FTP server, but its always 0 bytes. Please give me a solution for the file upload to work successfully.

I keep getting this warning:

Warning: ftp_put (): the PORT command succeeded in C: \ xampp \ htdocs \ mailing \ teskirim-file-simpan2.php on line 30
FTP upload failed!

enter image description here

My script:

<?php
$ftp_server = "********";
$ftp_serverpath = "ftp.".$ftp_server;
$ftp_user_name = "********";
$ftp_user_pass = "***********";
$email_dir = "*******@*********";

$nyambungkeftp = ftp_connect($ftp_server);
if (false === $nyambungkeftp) {
    throw new Exception('Unable to connect');
}

$loggedInnyambungkeftp = ftp_login($nyambungkeftp,  $ftp_user_name,  $ftp_user_pass);
if (true === $loggedInnyambungkeftp) {
    echo 'Success!';
} else {
    throw new Exception('Unable to log in');
}

if ((!$nyambungkeftp) || (!$loggedInnyambungkeftp)) { 
        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";
    }

// upload the file
$dest = 'detectip.txt';
$source = 'C:\xampp\htdocs\persuratan\file2\detectip.txt';

echo $dest;
echo $source;
$upload = ftp_put($nyambungkeftp, $dest, $source, FTP_ASCII); 


// check upload status
if (!$upload) { 
        echo "FTP upload has failed!";
    } else {
        echo "Uploaded $source_file to $ftp_server as $destination_file";
    }

// close the FTP stream 
ftp_close($nyambungkeftp); 

?>
+7
source share
2 answers

PHP is active by default in FTP mode. Nowadays, the active mode practically does not work due to the ubiquitous firewalls / NAT / proxies.

You almost always need to use passive mode.

To do this, call ftp_pasvafter ftp_login:

ftp_pasv($nyambungkeftp, true);

. FTP-, , .

+14

:

  • FTP_BINARY FTP_ASCII
+4

Source: https://habr.com/ru/post/1657207/


All Articles