Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
- Configure server to use php 8.0
- Configure FTP destination
- 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".
Comment | File | Size | Author |
---|---|---|---|
#7 | backup-migrate-3305432-07.patch | 1.85 KB | BrankoC |
|
Comments
Comment #2
thor10 CreditAttribution: thor10 as a volunteer commentedDrupal 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
Comment #3
quimicI confirm the exact same problem. All interaction with FTP (including backups) generate that same error.
Comment #4
BrankoC CreditAttribution: BrankoC as a volunteer commentedThe PHP manual says about ftp_systype():
Comment #5
BrankoC CreditAttribution: BrankoC as a volunteer commentedI can confirm this error.
How to reproduce:
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.
Comment #6
BrankoC CreditAttribution: BrankoC as a volunteer commentedComment #7
BrankoC CreditAttribution: BrankoC as a volunteer commentedTurns 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.
Comment #8
smitty CreditAttribution: smitty commentedThis patch works really fine! Thank you!
Comment #9
thor10 CreditAttribution: thor10 as a volunteer commentedRe: #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
Comment #10
BrankoC CreditAttribution: BrankoC as a volunteer commentedA 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.
Comment #11
thor10 CreditAttribution: thor10 as a volunteer commentedThanks 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.
Comment #12
DamienMcKennaThis looks reasonable.
Comment #14
DamienMcKennaCommitted. Thank you.