TMcCann's avatar

Multiple FTP errors on upload

I'm trying to upload a file to a remote FTP server using the following configuration:

'ftp' => [
            'driver' => 'ftp',
            'host' =>  env('FTP_HOSTNAME'),
            'username' => env('FTP_USERNAME'),
            'password' => env('PASSWORD'),
            'timeout' => 30,
        ],
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use File;
use Illuminate\Support\Facades\Storage;

class FtpTestController extends Controller
{
    public function saveFileToFTP() 
    {
        $localFile = File::get(storage_path('app/csv/test_1.csv'));

        Storage::disk('ftp')->put('test_4-23.csv', $localFile);
    }
}

It results in this error... local.ERROR: ftp_fput(): Type set to I.

I did some digging and it looks like a few issues were resolved setting the connection to passive. But when doing so I get this error...

Could not set passive mode for connection: example.com::21 at /var/www/html/example.com/vendor/league/flysystem/src/Adapter/Ftp.php:183)

0 likes
4 replies
psylogic's avatar

Well, you should turn off passive mode in your server. (ssh your server and type passive) then be sure that the dir you are uploading to is exists

TMcCann's avatar

@psylogic I've tried just about everything and I'm about to give up. I've logged in and changed from passive to active and back again with the same result. If I do a pwd command it returns

ftp> pwd
257 "/" is current directory.
ftp> 

the root is exactly where I want to place the file.

Also, even after changing back to active mode I'm still getting the same error. Is this cached somewhere?

psylogic's avatar
$conn_id = ftp_connect("IP");
ftp_login($conn_id, "username", "password");
dd(ftp_put($conn_id, 'newfilename', "yourfile", FTP_ASCII));

try this without using laravel FileSytem.. just to be sure if it works like so

TMcCann's avatar

@psylogic I did try that and it still failed. I was able to connect successfully but I couldn't upload or download. I finally figured it out. It was as simple as setting ssh => true & passive => true

1 like

Please or to participate in this conversation.