FTP error with PHP 8.0

Created on 23 August 2022, almost 2 years ago
Updated 28 April 2024, 2 months ago

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".
πŸ› Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

πŸ‡«πŸ‡·France quimic Paris

Live updates comments and jobs are added and updated live.
  • PHP 8.0

    The issue particularly affects sites running on PHP version 8.0.0 or later.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡«πŸ‡·France quimic Paris

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

  • πŸ‡³πŸ‡±Netherlands BrankoC

    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.

  • πŸ‡³πŸ‡±Netherlands BrankoC

    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.

  • πŸ‡³πŸ‡±Netherlands BrankoC
  • Status changed to Needs review 6 months ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 7.x + Environment: PHP 7.4 & MySQL 5.7
    last update 6 months ago
    26 pass
  • πŸ‡³πŸ‡±Netherlands BrankoC

    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.

  • πŸ‡©πŸ‡ͺGermany smitty

    This patch works really fine! Thank you!

  • πŸ‡©πŸ‡ͺGermany thor10

    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

  • πŸ‡³πŸ‡±Netherlands BrankoC

    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.

  • πŸ‡©πŸ‡ͺGermany thor10

    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.

  • Status changed to RTBC 2 months ago
  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    This looks reasonable.

  • Status changed to Fixed 2 months ago
  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    Committed. Thank you.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024