Skip to content
Advertisement

Why is my ftp connection not working in php laravel but is working in FileZilla?

I have a PHP Laravel (5.6) system that I need to connect to an FTP server to upload a single file. The FTP server that I am connecting to is restricting access by ip address, uses port 990, and other than that has a seemingly simple configuration. On my local machine (I’m running on Linux Ubuntu if that helps) I am able to connect to the ftp server in FileZilla just fine, FileZilla did seem to automatically choose ftps. I am also able to ping this server.

Now this PHP Laravel (5.6) application is running on NGINX (had this for a while, everything else server-wise seems fine). As of now I am just trying to get this working locally, though there is a production server that it will have to be pushed onto (pretty much identical configuration though).

I started out trying to use the built in PHP function ftp_connect and ftp_ssl_connect – both using the same host and port number (990) as in FileZilla. I have been unable to get past this step – it returns false (so never even gets to my login logic).

$ftp = ftp_connect(env('FTP_HOST'),env('FTP_PORT')); // returns FALSE
$ftp = ftp_ssl_connect(env('FTP_HOST'),env('FTP_PORT')): // returns FALSE

After searching for a while I decided to try Laravel’s filesystem to see if that would make it easier, these are my settings in config/filesystems.php:

'ftp' => [
            'driver' => 'ftp',
            'host' => env('FTP_HOST'),
            'username' => env('FTP_USER'),
            'password' => env('FTP_PASSWORD'),
            'port' => env('FTP_PORT'),
            'ssl' => true,
            'timeout' => 60,
        ],

'sftp' => [
            'driver' => 'sftp',
            'host' => env('FTP_HOST'),
            'username' => env('FTP_USER'),
            'password' => env('FTP_PASSWORD'),
            'port' => env('FTP_PORT'),
            'timeout' => 60,
        ],

I figured I’d try both ftp and sftp here, I then tried the following:

Storage::disk('ftp')->put('test.csv', $file);

and

Storage::disk('sftp')->put('test.csv', $file);

The first just timed out, the second gave me the message: LeagueFlysystemSftpConnectionErrorException: Could not login with username: ###, host: ### in…

Any ideas of what this could be or next steps I could take towards troubleshooting would be greatly appreciated, I feel like I just don’t know what to try to get a better understanding of what’s wrong here. Thanks!

EDIT: I realized that previously I had always used the quick connect feature in FileZilla for this. I looked into it further and was able to confirm that the encryption has to be implicit FTP over TLS – So I’m wondering if there is a setting for that I’m missing.

Advertisement

Answer

The port 990 is for implicit TLS/SSL, as you have eventually figured out.

The implicit TLS/SSL is not supported by the PHP built-in FTP implementation. Neither is implicit TLS/SSL supported by flysystem used by Laravel (which probably internally uses PHP built-in FTP anyway).

The implicit TLS/SSL was a temporary hack back in 90s to allow legacy FTP software to use encrypted connection without modification. It was never something that should have been used in long term, definitely not 30 years later! The implicit FTP never even became part of FTP standard. Only the explicit TLS/SSL was standardized by RFC 4217 in 2005. Since then, noone should be using implicit TLS/SSL ever.

Get your FTP server fixed to use the explicit TLS/SSL.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement