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:
if ( ! defined( 'FS_METHOD' ) ) define( 'FS_METHOD', 'direct' );
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:
- 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. - 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.
- 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.
- 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. - ftp (deprecated): This method uses FTP for file operations but is considered less secure than
ftpext
orftpsockets
. 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
Leave a Reply