broken plate on the floor

PHP fatal error: Uncaught TypeError: ftp_nlist(): Argument #1 ($ftp) must be of type FTP\Connection, null given

By

in ,

After moving a WordPress installation to another server, the following error showed up:

PHP fatal error: Uncaught TypeError: ftp_nlist(): Argument #1 ($ftp) must be of type FTP\Connection, null given

The new server had a different linux distribution and a newer PHP version. In my case, the environment changed from PHP 7.4 to PHP 8.2.

I already added some missing PHP extensions and updated the configuration to match the old one, but the error still exists.

At the end, this could be solved by adding the following code in wp-config.php file:

PHP
if ( ! defined( 'FS_METHOD' ) ) define( 'FS_METHOD', 'direct' );

Source

What is FS_METHOD in WordPress?

In WordPress, FS_METHOD is a constant that defines the method used for file system access when performing filesystem operations such as installing plugins, themes, or updating WordPress core.

The possible values for FS_METHOD are:

  1. direct: This method uses PHP‘s copy() function for file operations. It’s the simplest method but may not work on all servers due to server configuration restrictions.
  2. ssh2: This method uses SSH PHP extension for file operations. It requires SSH credentials and is suitable for situations where direct file access is not available or secure.
  3. ftpext: This method uses FTP PHP extension for file operations. It requires FTP credentials and is useful when neither direct file access nor SSH access is available.
  4. ftpsockets: Similar to ftpext, this method also uses FTP for file operations but does so via sockets. It’s used when the server doesn’t have the FTP PHP extension installed.
  5. ftp (deprecated): This method uses FTP for file operations but is considered less secure than ftpext or ftpsockets. It’s deprecated and should be avoided if possible.

The choice of FS_METHOD depends on the server configuration and security considerations. It’s typically defined in the wp-config.php file of a WordPress installation.

Foto von CHUTTERSNAP auf Unsplash



Comments

2 responses to “PHP fatal error: Uncaught TypeError: ftp_nlist(): Argument #1 ($ftp) must be of type FTP\Connection, null given”

  1. Thanks, this worked for me!

  2. You are awesome, I was getting this error while I run cron commands and console commands. Thank you very much.

Leave a Reply

Your email address will not be published. Required fields are marked *