Adding FTP access to the media repository
In the next few recipes, we will cover some FTP-related tasks, starting with the basic job of downloading files through FTP. This procedure can be used to synchronize files from a remote location with your website.
In this recipe, we will connect to ftp.software.ibm.com, which allowed anonymous access at the time of writing, and download the annual report.
Getting ready
Make sure PHP is configured with FTP support. If you go to the Install Tool module phpinfo(), you should see this output:
We will assume all directory paths exist—so if they don't, either change the values in the code, or create the necessary local folders (specifically ibm
under fileadmin
).
How to do it...
Create a plug-in, module, or a CLI script with the following code:
$connection = ftp_connect('ftp.software.ibm.com'); $email = !empty($GLOBALS['BE_USER']['user']['email']) ? $GLOBALS['BE_USER']['user']['email'] : 'foo@example.org'; $login = ftp_login($connection, 'anonymous', $email)...