keepcalculator

06 Numbers and Powers

Fix WordPress FTP Credentials Not Working on One Site

Card No. 06·41144 · Updated · Standard formula, shown below

If your WordPress site is asking for FTP credentials during updates or installations and they are not working, the fix is usually to add the correct FTP constants to your wp-config.php file, or to switch to a more reliable connection method like SFTP or direct filesystem access. This article explains why this happens, how to fix it, and how to avoid the problem in the future.

Why WordPress Asks for FTP Credentials

WordPress uses the Filesystem API to write files (e.g., when installing plugins, themes, or updating core). By default, it tries to write directly using the same user that runs the web server. If that user does not have permission to write to the WordPress directory, WordPress falls back to asking for FTP credentials so it can connect as a user that does have write access. This often happens on shared hosting, where the web server runs as a different user (e.g., nobody or www-data) than your FTP account.

If the credentials you enter are not working, it could be because the FTP account is not configured correctly, the server does not support the FTP protocol, or the WordPress site is configured to use a different connection method than what your host provides.

First, Verify Your FTP Credentials

Before editing any files, make sure the FTP credentials themselves are correct. Test them with a standalone FTP client (like FileZilla) to confirm they work. Common issues include:

  • Using the wrong username (often your cPanel username, not your email).
  • Using the wrong port (21 for FTP, 22 for SFTP, sometimes 990 for FTPS).
  • Your host may have disabled FTP and only offers SFTP or SSH.
  • Your FTP account may be limited to a specific directory (e.g., public_html) and cannot access the WordPress root.

If the credentials work in a client but not in WordPress, the problem is likely not the credentials themselves but how WordPress is trying to use them.

Add FTP Constants to wp-config.php

The most direct fix is to tell WordPress exactly how to connect by adding constants to your wp-config.php file. This file is located in the root of your WordPress installation. You can edit it via your hosting file manager or an FTP client.

Add the following lines, replacing the placeholders with your actual details:

define('FTP_HOST', 'ftp.example.com');
define('FTP_USER', 'your_ftp_username');
define('FTP_PASS', 'your_ftp_password');
define('FTP_SSL', false); // set to true if you use FTPS

If your host uses SFTP (FTP over SSH), you also need to define the SSH key path (if using key-based authentication) or use the FTP_PUBKEY and FTP_PRIKEY constants. However, many hosts do not support SFTP via the Filesystem API. In that case, you may need to use the FS_METHOD constant.

Set FS_METHOD to ‘direct’

If your web server user has write permissions to the WordPress files, you can bypass FTP entirely by forcing WordPress to use the direct method. Add this line to wp-config.php:

define('FS_METHOD', 'direct');

This tells WordPress to try to write files directly using the web server user. If that user does not have write permissions, you will get a “Could not create directory� error. To make it work, you need to ensure the web server user owns the WordPress files or at least has write access to the directories where updates and installs occur (usually wp-content and its subdirectories).

On many shared hosts, you can change file ownership via the file manager or by running a command like chown -R www-data:www-data /path/to/wordpress if you have SSH access. If you don’t, you may need to ask your host to do it.

Use SFTP or SSH Instead of FTP

FTP is an old, insecure protocol. Many hosts now disable it and only offer SFTP (which uses SSH) or FTPS (FTP over SSL). WordPress supports these via the Filesystem API, but you need to specify the correct connection type. Add these constants:

define('FS_METHOD', 'ftpsockets'); // for FTPS
define('FTP_HOST', 'ftp.example.com');
define('FTP_USER', 'your_username');
define('FTP_PASS', 'your_password');

For SFTP, you need to use the ssh2 extension in PHP, which is not always enabled. If it is, you can use:

define('FS_METHOD', 'ssh2');
define('FTP_HOST', 'ftp.example.com');
define('FTP_USER', 'your_username');
define('FTP_PASS', 'your_password');

But note that SFTP via the Filesystem API often requires key-based authentication, not just a password. Check your host’s documentation.

Common Causes of FTP Credential Failure

  • Firewall or IP restrictions: Some hosts block FTP connections from certain IPs. If you are using a VPN or a different IP, try disabling it.
  • Passive vs. Active mode: WordPress uses passive mode by default. If your host requires active mode, you may need to change a setting, but WordPress does not expose this. You can try using the FTP_PASSIVE constant (set to false) to force active mode.
  • Wrong port: Some hosts use a non-standard port for FTP. You can specify the port by appending it to the host, e.g., ftp.example.com:21.
  • FTP server not running: If your host has not started the FTP service, you will get a connection error. Check with your host.
  • File permissions: Even if FTP connects, if the target directory is not writable by the FTP user, you will get a permission error. Ensure the FTP user has write access to the WordPress directory.

Alternative: Use a Plugin or Hosting Panel

If editing wp-config.php is too technical, you can try a plugin like “WP FTP Connection� that lets you set FTP credentials from the admin dashboard. However, these plugins often just write the same constants to the config file, so it is equivalent.

Another alternative is to use your hosting control panel (like cPanel) to install plugins or themes directly, bypassing WordPress’s filesystem entirely. Many hosts also offer a “one-click� update feature that does not require FTP.

Frequently Asked Questions

Why does WordPress ask for FTP credentials even though I have the correct permissions?

This usually happens because the web server user (e.g., www-data) is not the owner of the WordPress files. Even if your FTP user can write, WordPress does not use that user by default. Setting FS_METHOD to direct and ensuring the web server user has write permissions is the fix.

Can I use the same FTP credentials as my hosting account?

Yes, usually the FTP credentials are the same as your hosting account, but not always. Some hosts create separate FTP accounts. Check your hosting welcome email or control panel.

What does the FTP_HOST constant look like?

It is the hostname of your FTP server, often something like ftp.yourdomain.com or localhost if you are on a local server. You can find it in your hosting control panel or by using an FTP client to connect and looking at the server address.

Is it safe to store FTP passwords in wp-config.php?

It is not ideal, but it is common. The file is not publicly accessible (if your server is configured correctly), but it is a plain text file. If your site is compromised, the password could be exposed. Consider using SFTP with key authentication or the direct method instead.

Why does the FTP connection time out?

This could be due to a firewall blocking the port, the server being down, or the host requiring a specific port. Try using a different port (e.g., 21 for FTP, 22 for SFTP) or contact your host.

What if I don’t know my FTP password?

You can reset it via your hosting control panel. Many hosts allow you to change FTP passwords from the “FTP Accounts� section. If you do not have access, contact your host’s support.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →