2015-11-06 51 views
0

我編寫了Drupal模塊來查看某些目錄中的文件。如果文件存儲在Drupal文件夾「網站/默認/文件/ someimages」或FTP文件夾「ftp://someftp.com/someimages/」,一切工作正常!但是,如果FTP是通過用戶名和密碼保護的,在我的PHP模塊代碼發生錯誤:用Drupal站點的密碼訪問ftp文件夾

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文件夾?

回答

0

難道你不能只是像這樣添加用戶名和密碼?所以你可以授權?

ftp://username:[email protected]/path1/path2/ 

由於altetnative,嘗試使用功能

<?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 [email protected]$ftp_server\n"; 
} else { 
    echo "Couldn't connect as $ftp_user\n"; 
} 

// close the connection 
ftp_close($conn_id); 
?> 
相關問題