Enable SFTP and SSH updates to WordPress Core, Themes and Plug-ins
Enable SFTP in WordPress for updates.
I recently kept receiving the ‘Failed to connect to FTP Server‘ error when trying to update to WordPress 3.3.2. I had recently moved from shared hosting to a VPS running Ubuntu and Plesk. I had double checked the FTP user and password in Plesk control panel and even created a user just for this very purpose but still it failed. I then tried connecting with FileZilla using FTP and I couldn’t. I always use SSH to connect to the server and so I hadn’t even noticed that no FTP server was running (some digging after solving this problem made me find that it was running, just running on non default ports -which is a good thing ).
So the situation I was in was: WordPress Core update and the only way of doing so was via manually uploading the files through SFTP which I was able to connect to via FileZilla.
I really didn’t like the idea of doing that with over a dozen different WordPress instances so I found a slightly better way. Enable SFTP over SSH in my WordPress install. After a little bit of thought and some searching I found that Jon over at Snowulf had found the exact solution that I was looking for. He even had the exact commands to issue in a shell terminal on my server. All I had to do was install “libssh2-php which is the PHP bindings for libssh2” and restart Apache. It worked a treat and I now perform all my automatic installs and updates over a much more secure connection. Thanks for this, Jon. I also left him a little note on the page to say thanks there too because this not only fixes my problem it also improves upon the normal behaviour of WordPress in this situation .
Installing libssh2.php is a piece of cake on Ubuntu, just connect to your server however you like and run these commands:
apt-get install libssh2-php /etc/init.d/apache2 restart
If you run a distro other than Ubuntu then you should still be able to find ssh2 by searching your package manager for “libssh2“, installing and then restarting Apache.
Next time you see the FTP connection screen you will have the choice of connecting via SSH which will use SFTP. All you need to enter is your username, password and secure keys if you have them set up and treat it the same as the old FTP upload screen provided in WordPress.
It seems strange to me that this isn’t included in the Core of WordPress as I haven’t used FTP as my primary connection measure for a long time now and even when it was my primary method I still never used the default ports.