Upload file FTP with Filesystem Laravel error - laravel

I try to upload a video file to my download server with FTP file system in laravel but I have a this error:
League\Flysystem\ConnectionRuntimeException: Could not connect to host: myip, port:21 in file /home/test/domains/myhost/laravel/vendor/league/flysystem/src/Adapter/Ftp.php on line 140
in my filesytem.php
'ftp' => [
'driver' => 'ftp',
'host' => 'myip',
'username' => 'myusername',
'password' => 'mypass',
'port' => 21,
],
how to fix this error

FTP port:21 is for pass control information.
Did you try port:20 ?

im using sftp because when i using ftp is error in port too. and don't forget too enable ftp in php.ini
'sftp' => [
'driver' => 'sftp',
'host' => 'xxx.xxx.com',
'username' => 'user',
'password' => 'pass',
'root' => ' xxx' , // for example: /public_html/images

I fix this issue by enabling an FTP extension in my server.

Related

Laravel 9 sFTP Unable to write file at location text.txt. not able to write the file

I am trying to create a file on a sFtp server:
Storage::disk('backup')->put('text.txt', 'My Text');
Unfortunately, I only get the following error message back, which I can't do anything with:
League\Flysystem\UnableToWriteFile
Unable to write file at location: text.txt. not able to write the file`
I have checked the permissions for the directory, they are ok.
My Filesystem config:
'backup' => [
'driver' => 'sftp',
'host' => env('SFTP_HOST'),
// Settings for basic authentication...
'username' => env('SFTP_USERNAME'),
'password' => env('SFTP_PASSWORD'),
'throw' => true,
],

Cannot Create SSL client. SSL not enabled in build

I've been migrating databases from mLab to MongoDB Atlas (mLab is being terminated Nov 10th). I've been trying to put make a mongo url dsn connection to connect to my Atlas cluster. However, when I put in the connection, I get this error:
MongoDB \ Driver \ Exception \ InvalidArgumentException
Cannot create SSL client. SSL is not enabled in this build.
I have been told this is how you connect to MongoDB Atlas from this source stackoverflow post
Database.php:
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],
'mongodb' => [
'driver' => 'mongodb',
'dsn'=> env('DB_DSN'),
'database' => env('DB_DATABASE'),
],
my .env file:
DB_DSN=mongodb://****username:****password#*****-shard-00-00.d4sg0.mongodb.net:27017,*****-shard-00-01.d4sg0.mongodb.net:27017,*****-shard-00-02.d4sg0.mongodb.net:27017/****database?ssl=true&replicaSet=atlas-xn698l-shard-0&authSource=admin&retryWrites=true&w=majority
Project Specs:
Laravel,
Apache,
MongoDB,
Composer using Git Bash

Laravel FTP - Root path for windows server

I am trying to upload a file from my local to FTP server using laravel
'ftp' => [
'driver' => 'ftp',
'host' => env('FTP_HOST'),
'username' => env('FTP_USERNAME'),
'password' => env('FTP_PASSWORD'),
'port' => '21',
'passive' => false,
'root' => 'c:/POSActiveAutoInsert/WEBSales_In/' // for example: /var/www/html/dev/images
//
],
In my controller
Storage::disk('ftp')->put('test.txt', $file);
But when I run this, it says
Root is invalid or does not exist: c:/POSActiveAutoInsert/WEBSales_In/
I have tried FTP using Filezilla it works fine
The FTP account I am using takes you directly to c:/POSActiveAutoInsert/WEBSales_In/ this folder. This WEBSales_In is the root folder for this FTP user that I am using. Can't figure out what the root path would be, or am I doing something wrong other than this.
Cheers
You can try this in your controller
$path = $request->your_variable_name->storeAs('text', '$file', ['disk' => 'ftp']);

Laravel Storage method allDirectories() does not return recursively directories from FTP server

I need to get list of all directories from the FTP server.
After successful FTP driver setup, Storage::allDirectories() method is returning all directories from root directory. I have also tried to use:
Storage::directories('/', true)
Which should also return recursive values but it's the same case.
Does anyone have any idea what should be problem?
This is my FTP connection setup:
$ftp = Storage::createFtpDriver([
'host' => $streamServer->url,
'username' => $streamServer->username,
'password' => $streamServer->password,
'port' => '21',
'timeout' => '30',
]);
Welcome to Stackoverflow
I have checked with my code and it's working when I added the following line in my filesystems.php
I have created ftp driver in filesystems as below.
'ftp' => [
'driver' => env('DOCUMENT_UPLOAD_DRIVER','sftp'),
'host' => env('DOCUMENT_UPLOAD_HOST','127.0.0.1'),
'username' => env('DOCUMENT_UPLOAD_USERNAME','root'),
'password' => env('DOCUMENT_UPLOAD_PASSWORD','root'),
'root'=> env('DOCUMENT_UPLOAD_ROOT', '/var/www/html')
'port' => env('DOCUMENT_UPLOAD_PORT', 22),
'timeout' => env('DOCUMENT_UPLOAD_TIMEOUT', 30),
],
this line is additionaly added.
'root'=> env('DOCUMENT_UPLOAD_ROOT', '/var/www/html')
and when I use the following command it works for me.
Storage::disk('ftp')->allDirectories('directoryName');
provide directory name from which you want to get list or leave blank will provide you the list of all the recursive directories from html directory because we have provided it as a root.
after that you need to extract directories manually, as it just gives you an array like namespace will all the recursive directories.

Laravel 5l Multiple Database Connections

Do I need to have my DB connection info in 2 places? If I do the below, I connect just fine. If I remove either file's data, I can't connect.
config/databases.php file
'blah_1' => [
'driver' => 'mysql',
'host' => env('DB_HOST’,’1.1.1.1’),
'port' => env('DB_PORT','3306'),
'database' => env('DB_DATABASE’,’someDB_1’),
'username' => env('DB_USERNAME’,’someUser_1’),
'password' => env('DB_PASSWORD’,’somePass_1’),
],
'blah_2' => [
'driver' => 'mysql',
'host' => env('DB_HOST_SECOND’,’2.2.2.2’),
'port' => env('DB_PORT_SECOND','3306'),
'database' => env('DB_DATABASE_SECOND’,’someDB_2’),
'username' => env('DB_USERNAME_SECOND’,’someUser_2’),
'password' => env('DB_PASSWORD_SECOND’,’somePass_2’),
],
.env file:
DB_CONNECTION=blah_1
DB_HOST=1.1.1.1
DB_PORT=3306
DB_DATABASE=someDB_1
DB_USERNAME=someUser_1
DB_PASSWORD=somePass_1
DB_CONNECTION_SECOND=blah_2
DB_HOST_SECOND=2.2.2.2
DB_PORT_SECOND=3306
DB_DATABASE_SECOND=someDB_2
DB_USERNAME_SECOND=someUser_2
DB_PASSWORD_SECOND=somePass_2
The short answer is no. You only need it in your config/databases.php. The .env file is to overwrite the settings in your other environments without updating the configuration file.
For example, in your local environment, your credentials is most likely different from your production environment. You wouldn't want to update config/databases.php locally and remind yourself to not push the file.
However, the connections would still work even if remove them from the .env file. It will use the second parameter's value in your env() as default.

Resources