繁体   English   中英

PHP FTP:访问被拒绝

[英]PHP FTP : Access Denied

我正在从我的php页面上进行FTP上传。

<?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);
 ?>

它在浏览器中给我一个警告

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

我检查了文件的访问权限。 但它可以访问。 任何人都可以告诉我为什么会这样吗?

最有可能这是一个许可问题。 当您通过FTP上传文件时,还需要检查目录的权限。 当你说它可以访问时,并不意味着它是可写的。

您不检查登录操作的结果:

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";
}

您还应该尝试从PHP主机到FTP主机的手动FTP操作,以确保您可以使用这些凭据登录并放置文件。 这将帮助您确定它是您的错误代码还是FTP凭据。

           <?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);

          }
            }
          ?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM