PHP ftp_put - file not found or missing access

How should I handle files that are not in the current directory when using ftp_put? This piece of code is trying to load a file that I know, but it always gives the following error:

"Warning: ftp_put () [function.ftp-put]: the requested action did not complete, the file was not found or access is denied. In /path/to/files/domains/mydomain.com/html/scriptfile.php on line 1337"

Here's the snip:

$file_name = $this->GetFileName();

  if ($file_name)
  {
    $resource = ftp_connect('ftp.remoteftpserver.com');    

    if ($resource && ftp_login($resource, $username, $pass))
    {
      ftp_pasv($resource, true);
      //UPLOAD_DIRECTORY == '/IN' (it really exists, I'm sure)
      //ORDER_DIRECTORY == /home/domains/mydomain.com/orders (came from $_SERVER['DOCUMENT_ROOT']
      ftp_put($resource, UPLOAD_DIRECTORY . '/' . $file_name, ORDER_DIRECTORY . '/' . $file_name, FTP_ASCII);

      ftp_close($resource);
    }
    else
    {
      echo "FTP Connection Failed!";
    }

  }
+3
source share
1 answer

Check the permissions of the deleted file. Make sure $ username has write access to the file. Make sure you have execute access in the parent directory.

+1
source

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


All Articles