What role does passive mode play in FTP connections and how can setting ftp_pasv to false potentially impact the functionality of ftp_rawlist in PHP?

When FTP connections are made in passive mode, the client opens a data channel for transferring files, which can be beneficial for connections behind firewalls. Setting ftp_pasv to false in PHP can potentially impact the functionality of ftp_rawlist as it may not be able to retrieve directory listings properly. To solve this issue, ensure that ftp_pasv is set to true before calling ftp_rawlist.

// Connect to FTP server
$ftp = ftp_connect('ftp.example.com');

// Login to FTP server
ftp_login($ftp, 'username', 'password');

// Set passive mode to true
ftp_pasv($ftp, true);

// Get raw directory listing
$rawList = ftp_rawlist($ftp, '/path/to/directory');

// Close FTP connection
ftp_close($ftp);