使用PHP脚本拒绝FTP权限

时间:2015-05-23 04:38:47

标签: php ftp permissions

我的ftp帐户有问题。这是我编写的用于连接到FTP并创建文件夹的代码:

<?php 
$ftp_server = "xxxxxxxxxxxxxxx";
$ftp_username = 'xxxxxxxx';
$ftp_password = 'xxxxxxxxxxxxxxx';

$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, $ftp_username, $ftp_password);

// try to create directory $path
$path = '/2/7/7';
if(ftp_mkdir($ftp_conn, $path)) {
    echo 'done';
    die();
}
echo 'error';
?>

运行代码时出现以下错误:

  

警告:ftp_mkdir():权限被拒绝

当我使用filezilla或其他ftp管理器应用程序时,我可以轻松创建一个文件夹但是在使用脚本处理它时会出现问题。我告诉我的网络管理员确保该帐户是否具有读写权限。他们说已经设置了读写权限。我想它可能还需要执行权限,可能没有设置。

有没有办法使用php脚本检查权限?我还尝试使用filezilla检查文件夹权限,但它显示如下:

enter image description here

1 个答案:

答案 0 :(得分:-1)

尝试使用此解决方案recursive-ftp-make-directory

// recursive make directory function for ftp
function make_directory($ftp_stream, $dir)
{
// if directory already exists or can be immediately created return true
if (ftp_is_dir($ftp_stream, $dir) || @ftp_mkdir($ftp_stream, $dir)) return true;
// otherwise recursively try to make the directory
if (!make_directory($ftp_stream, dirname($dir))) return false;
// final step to create the directory
return ftp_mkdir($ftp_stream, $dir);
}

function ftp_is_dir($ftp_stream, $dir)
{
// get current directory
$original_directory = ftp_pwd($ftp_stream);
// test if you can change directory to $dir
// suppress errors in case $dir is not a file or not a directory
if ( @ftp_chdir( $ftp_stream, $dir ) ) {
// If it is a directory, then change the directory back to the original directory
ftp_chdir( $ftp_stream, $original_directory );
return true;
} else {
return false;
}
}
不要忘记为新的递归目录添加$dir='2/3/4/5/6'