PHP:从FileZilla Server获取文件[重复]

问题描述 投票:0回答:1

这个问题在这里已有答案:

我希望通过PHP连接另一台服务器。我的PHP代码是:

// FTP server details
$ftpHost   = 'server4.streamserver24.com';
$ftpUsername = '';
$ftpPassword = '*****';

// open an FTP connection
$connId = ftp_connect($ftpHost) or die("Couldn't connect to $ftpHost");

// login to FTP server
$ftpLogin = ftp_login($connId, $ftpUsername, $ftpPassword);

在连接之后,我想从此服务器中的文件夹名称“mp3”获取文件。我尝试过的:

$sDir = 'mp3/';
$rDir = opendir($sDir);
php server ftp connect filezilla
1个回答
0
投票
// FTP server details
$ftpHost   = 'server4.streamserver24.com';
$ftpUsername = '';
$ftpPassword = '*****';

// open an FTP connection
$connId = ftp_connect($ftpHost) or die("Couldn't connect to $ftpHost");

// login to FTP server
$ftpLogin = ftp_login($connId, $ftpUsername, $ftpPassword);

// get contents of the directory mp3
$contents = ftp_mlsd($connId , "mp3");

foreach($contents as $file_or_directory){
    if($file_or_directory['type'] == 'file'){ // only files
          print_r($file_or_directory);
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.