FTP 权限被拒绝使用 php 脚本

FTP permission denied using php script

我的 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';
?>

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

Warning: ftp_mkdir(): Permission denied

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

有什么方法可以使用 php 脚本检查权限吗?我还尝试使用 filezilla 检查文件夹权限,但它显示如下内容:

试试这个解决方案吧 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'