0

I wrote a PHP script to upload a specific file in a folder to FTP server, The problem here is that ftp_put method will not upload the file and will echo the error message, however ftp_nb_put method can successfully upload the file instead. Does anyone have any idea why put method will not work but using nb will make it work instead? I should also mention that I am already logged in as a user with full control of permission of the FTP server.

Below is the code for my ftp_put file uploading to FTP server. When I use ftp_put it will only echo the error message under the if statement. However, when ftp_nb_put is used the php file will start loading indefinitely, but the file will be uploaded into the folder of the FTP server. I am trying to upload an excel file that has no attributes enabled in its properties.

$remote_file = './PROCESS CHECKSHEET/0694384-000-AA2.xlsx';
$local_file = './PROCESS CHECKSHEET/0694384-000-AA2.xlsx';
$upload = ftp_put($ftpcon, $remote_file, $local_file, FTP_BINARY);

if (!$upload) {
    echo "File uploaded successfully to FTP server!";
} else {
    echo "Error uploading file! Please try again later.";
}

ftp_close($ftpcon);

Edit: I found out that ftp_put method does indeed work, but the fact that it output the error message misled me into thinking that it did not work. Why would it not echo the success message but echo the error message instead? When I delete the error message line from the script, it will only output a blank page.

Rillu
  • 9
  • 2

0 Answers0