Problem/Motivation

Using php 8.0 seems to break FTP. Trying to create a new FTP backup or to list saved backups results in the following error:
TypeError: ftp_systype(): Argument #1 ($ftp) must be of type resource, null given in ftp_systype() (line 200 of my_site_root/sites/all/modules/contrib/backup_migrate/includes/destinations.ftp.inc).

Switching php to 7.4 restores FTP communication.

Steps to reproduce

  1. Configure server to use php 8.0
  2. Configure FTP destination
  3. Create a backup to FTP destination

Alternately, the last step can also be:

  • Go to admin/config/system/backup_migrate/backups, or
  • Open Backup Settings and under your FTP destination, click "list files".
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quimic created an issue. See original summary.

thor10’s picture

Drupal core 7.92
Backup and Migrate 7.x-3.10

I have updated the web server from PHP 7.4 to PHP 8.0

Now, when calling

admin/config/system/backup_migrate/backups

the following error message appears

TypeError: ftp_systype(): Argument #1 ($ftp) must be of type resource, null given in ftp_systype() (line 200 of /mydomain/sites/all/modules/backup_migrate/includes/destinations.ftp.inc).

Does anyone know how I can work around or fix this?

Greetings

Translated with DeepL.com/Translator

quimic’s picture

I confirm the exact same problem. All interaction with FTP (including backups) generate that same error.

BrankoC’s picture

The PHP manual says about ftp_systype():

Changelog:
PHP 8.1.0. The ftp parameter expects an FTP\Connection instance now; previously, a resource was expected.

BrankoC’s picture

I can confirm this error.

How to reproduce:

  1. Create an FTP destination.
  2. Go to admin/config/system/backup_migrate/backups.

What happens in includes/destinations.ftp.inc is that the function responsible for creating a connection first tests if a connection already exists.

It does this by calling drupal_ftp_connected() with an incomplete $ftp object.

When that happened in PHP 7, PHP's ftp_systype() function was perfectly happy to test a non-existent resource, but in PHP 8, the same function does not like it when it receives a non-existent FTP\Connection instance.

When I change line 200 (inside the drupal_ftp_connected() method) from

if (!@ftp_systype($ftp->__conn)) {

to

if (!isset($ftp->__conn) || !ftp_systype($ftp->__conn)) {

(inserted: !isset($ftp->__conn) || ), this particular problem goes away, but a host of new ones pop up.

Unfortunately I do not have the time right now to look at this further. It looks like the whole include needs to be looked at to get FTP working again.

BrankoC’s picture

Issue summary: View changes
BrankoC’s picture

Version: 7.x-3.10 » 7.x-3.x-dev
Status: Active » Needs review
FileSize
1.85 KB

Turns out I had some time after all. This patch implements the suggestion of #5 and a small fix for a trivial problem where an error message wasn't shown.

The "host of [problems]" I was talking about in #5 were caused by me not having a proper FTP server to connect to. Those error messages went away when I introduced a working FTP destination. I will address them in a separate issue.

smitty’s picture

This patch works really fine! Thank you!

thor10’s picture

Re: #7

Hello BrankoC,

first of all, many thanks for your persistent commitment.

Unfortunately, I do not know where the file backup-migrate-3305432-07.patch has to be installed.

I am confident that I can do this with the right file via FTP, but I would be very happy if you could tell me which file* and how/where it has to be changed.

Best regards, thor10

* It could perhaps be with me: sites/all/modules/backup_migrate/includes/destinations.ftp.inc

Drupal 7.100
Backup and Migrate 7.x-3.10
PHP 8.1.15

Translated with DeepL.com

BrankoC’s picture

A patch needs to be applied, not installed.

Patches are a way for developers to publish code changes for review. When applied they change the files of the module. Here is the official documentation on how to apply patches and here is a Stackoverflow question on how to apply patches.

Patching is not for the faint of heart but with a little technical knowledge, courage and perseverance it is doable. :-)

If things go wrong, just replace the files from a fresh module download.

The code in the patch is work in progress, so it may not work or may have adverse effects. Ideally you test the patch on a copy of your site. Please report any things that go wrong (assuming you have successfully applied the patch) in this issue.

If the patch works for you, you may wish to apply it to your production environment. Any updates to the module will overwrite the patch. If those updates do not (yet) contain the changes from the patch, you may need to re-apply the patch.

thor10’s picture

Thanks BrankoC for the information and the links!

I'll see if I can perhaps work it out and then report back here.

As a layman, I would of course be very happy if your tests and results were incorporated into an update of the module by the responsible developers.

DamienMcKenna’s picture

Status: Needs review » Reviewed & tested by the community
Parent issue: » #3257631: Plan for Backup & Migrate 7.x-3.11

This looks reasonable.

  • DamienMcKenna committed 64b652ee on 7.x-3.x
    Issue #3305432 by BrankoC, quimic, thor10, DamienMcKenna: FTP error with...
DamienMcKenna’s picture

Title: FTP error with php 8.0 » FTP error with PHP 8.0
Status: Reviewed & tested by the community » Fixed
Issue tags: +PHP 8.0

Committed. Thank you.