I want to upload a file from Laravel
to another server using FTP
.
It seems a very simple task, so let’s take a look at my configurations:
.env file
FTP_HOST=dl.myserver.com
[email protected]
FTP_PASSWORD=somePass
filesystem.php
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'ftp' => [
'driver' => 'ftp',
'host' => env('FTP_HOST'),
'username' => env('FTP_USERNAME'),
'password' => env('FTP_PASSWORD'),
'passive' => true,
'port' => 21,
'root' => '/home/myserver/public_html/podcasts'
],
.
.
.
and my controller finally
$year = Carbon::now()->year;
$month = Carbon::now()->month;
$day = Carbon::now()->day;
//podcast
$podcast = $request->file('podcast');
$filename = $podcast->getClientOriginalName();
$purename = substr($filename, 0, strrpos($filename, '.'));
$filenametostore = $purename . '_' . $year .'_' . $month . '_' . $day . '.' . $podcast->getClientOriginalExtension();
Storage::disk('ftp')->put($filenametostore, fopen($request->file('podcast'), 'r+'));
.
.
.
but I have this error:
LeagueFlysystemConnectionRuntimeException
Could not log in with connection: dl.myserver.com::21, username:
[email protected]
My FTP
account and information is true because I logged in using FileZilla
.
As a mention, my dl.server.com
is using CPANEL
.
Is there any Idea about this issue?
Thanks in Advance
2
Answers
Surprisingly the problem solved when I replaced
env('FTP_HOST')
,env('FTP_USERNAME')
andenv('FTP_PASSWORD')
with equivalent string values infilesystems.php
file!I tried pure PHP
FTP functions
and figured it out:So my Laravel
filesystem.php
looks like this:and it works fine in my case.
You need to put the password with double quotes in your .env
Particularly if your password contains spaces or #
FTP_PASSWORD="some#Pass"