从 Drupal 站点使用密码访问 ftp- 文件夹

Access to ftp-folder with password from Drupal site

我编写了 Drupal 模块来查看某些目录中的文件。如果文件存储在 drupal 文件夹 "sites/default/files/someimages" 或 ftp 文件夹“ftp://someftp.com/someimages/”,一切正常!但是如果 ftp 受用户和密码保护,我的 php 模块代码就会出错:

warning: scandir(ftp://someftp.com/someimages/): failed to open dir: operation failed in /srv/www/vhosts/mysite.com/sites/all/modules/mymodule/mymodule.module on line 227.

如何接受我的 drupal 模块打开 ftp 文件夹的权限?

你不能像这样添加用户名和密码吗?所以你可以授权吗?

ftp://username:password@sld.domain.tld/path1/path2/ 

作为替代,尝试使用函数 ftp_login

<?php

$ftp_server = "ftp.example.com";
$ftp_user = "foo";
$ftp_pass = "bar";

// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); 

// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
    echo "Connected as $ftp_user@$ftp_server\n";
} else {
    echo "Couldn't connect as $ftp_user\n";
}

// close the connection
ftp_close($conn_id);  
?>