PHP FTP: Denial of Access

I worked with FTP upload from my php page.

<?php error_reporting(E_ALL); ini_set('display_errors', true); flush(); $ftp_server = "myserver"; $ftp_user_name="myuser"; $ftp_user_pass="mypass"; $remote_file="myfile.txt"; $file="myfile.txt"; // set up a connection or die $conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) { echo "successfully uploaded $file\n"; } else { echo "There was a problem while uploading $file\n"; } // close the connection ftp_close($conn_id); ?> 

This gives me a warning in the browser, for example

 Warning: ftp_put(): Access is denied. in /var/www/html/ftpcheck.php on line 17. There was a problem while uploading myfile.txt. 

I checked the file permissions. But its available. Can someone tell me why this is happening?

+4
source share
3 answers

This is most likely a resolution issue. When you upload a file via FTP, you also need to check the directory permissions. When you say that it is available, it does not mean that it is available for recording.

+3
source

You do not check the result of the login operation :

 if (ftp_login($conn_id, $ftp_user_name, $ftp_user_pass)) { echo "Connected as $ftp_user_name@ $ftp_server\n"; } else { echo "Couldn't connect as $ftp_user_name\n"; } 

You should also try a manual FTP operation from the PHP host to the FTP host to make sure that you can log in with these credentials and place the file. This will help you determine if your code is bad or FTP credentials.

+1
source
  <?php class Ftp { function upload() { $ftp_server="50.56.113.39"; $ftp_user_name="******"; $ftp_user_pass="***"; $file = "form.pdf";//tobe uploaded $remote_file = "uploads1/test.pdf"; // set up basic connection $conn_id = ftp_connect($ftp_server); // login with username and password $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); // upload a file if (ftp_put($conn_id, $remote_file, $file, FTP_BINARY)) { echo "successfully uploaded $file\n"; //exit; } else { echo "There was a problem while uploading $file\n"; //exit; } // close the connection ftp_close($conn_id); } } ?> 
-1
source

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


All Articles