I'm trying to create a custom module that would connect to an external FTP and grab an XML file (provided by third party). This file can't be accessed through http.

In Drupal 8, there is the Drupal\Core\FileTransfer\FTP class, but I'm not sure as of how I could use it inside my custom module. I don't see any service I could use.

Do I use that class directly, or is there a service I need to use?


The information about the classes that extends FileTransfer() are returned from hook_filetransfer_info(), and altered by hook_filetransfer_info_alter(). There isn't any service to use.
As such, the code that uses that class should be similar to the following one.

$info = drupal_get_filetransfer_info();

if (!empty($info['ftp']) && $class = $info['ftp']['class']) {
  $ftp = $class::factory($jail, $settings);

Notice that when the patch in Convert hook_filetransfer_info() to plugin system will be applied to Drupal 8.x.3, the code I wrote will probably need to be changed, if the change is not going to be backward-compatible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.