PHP:从FileZilla服务器获取文件

时间:2019-02-19 16:43:02

标签: php server ftp connect filezilla

由于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);

1 个答案:

答案 0 :(得分: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);
    }
}