What role does the 'ftp_pasv()' function play in resolving issues related to FTP connections in PHP scripts?

When using FTP connections in PHP scripts, sometimes the connection may fail due to firewall restrictions or network configurations. One common solution to this issue is to use the 'ftp_pasv()' function to switch the FTP connection to passive mode, which can help bypass firewall restrictions and establish a successful connection.

// Create FTP connection
$ftp_conn = ftp_connect('ftp.example.com');

// Login to FTP server
$login = ftp_login($ftp_conn, 'username', 'password');

// Switch to passive mode
ftp_pasv($ftp_conn, true);

// Continue with FTP operations
// For example, list files in a directory
$files = ftp_nlist($ftp_conn, '/path/to/directory');

// Close FTP connection
ftp_close($ftp_conn);