laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.21k stars 10.9k forks source link

FTP storage put or move stopped working/changed after upgrading from laravel 8 to laravel 9 #42879

Closed karunkshrestha closed 2 years ago

karunkshrestha commented 2 years ago

Description:

The following command which simply retrieves the xml files and moves it an Archive folder in the ftp server works in laravel 8 but no longer works in laravel 9. I don't know what has changed in the adapter to cause it break.

`<?php namespace App\Console\Commands;

use Illuminate\Console\Command; use Illuminate\Support\Arr; use Illuminate\Support\Str; use Illuminate\Support\Facades\Storage;

class CopyXmlToLocalStorage extends Command { /**

Steps To Reproduce:

  1. use the composer.json
  2. copy the command
  3. create a directory named 'test' in the ftp server
  4. create a few xml files in the test directory
  5. create an archive folder test/Archive
  6. run the command php artisan xml:ftp-to-local --source=test

composer.json

{ "name": "laravel/laravel", "type": "project", "description": "The Laravel Framework.", "keywords": ["framework", "laravel"], "license": "MIT", "require": { "php": "^8.0.2", "guzzlehttp/guzzle": "^7.2", "laravel/framework": "^9.11", "laravel/sanctum": "^2.14.1", "laravel/tinker": "^2.7", "league/flysystem-ftp": "3.0", "spatie/laravel-google-cloud-storage": "^2.0", "spatie/laravel-schedule-monitor": "^3.0" }, "require-dev": { "fakerphp/faker": "^1.9.1", "laravel/sail": "^1.0.1", "mockery/mockery": "^1.4.4", "nunomaduro/collision": "^6.1", "phpunit/phpunit": "^9.5.10", "spatie/laravel-ignition": "^1.0" }, "autoload": { "psr-4": { "App\\": "app/", "Database\\Factories\\": "database/factories/", "Database\\Seeders\\": "database/seeders/" } }, "autoload-dev": { "psr-4": { "Tests\\": "tests/" } }, "scripts": { "post-autoload-dump": [ "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump", "@php artisan package:discover --ansi" ], "post-update-cmd": [ "@php artisan vendor:publish --tag=laravel-assets --ansi --force" ], "post-root-package-install": [ "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" ], "post-create-project-cmd": [ "@php artisan key:generate --ansi" ] }, "extra": { "laravel": { "dont-discover": [] } }, "config": { "optimize-autoloader": true, "preferred-install": "dist", "sort-packages": true }, "minimum-stability": "dev", "prefer-stable": true }

karunkshrestha commented 2 years ago

running the following command in laravel 9 and laravel 8 -> ftp log. Laravel 8 works correctly.

Storage::disk('ftp')->move('test/Host.xml', 'test/Archive/Host.xml');

running in laravel 9 - ftp log


> 220-FileZilla Server version 0.9.43 beta
> 220 ****
> USER ***
> 331 Password required for ***
> PASS ****
> 230 Logged on
> PASV
> 227 Entering Passive Mode (***)
> NOOP
> 200 OK
> CWD
> 250 Broken client detected, missing argument to CWD. "/" is current directory.
> CWD Archive
> 250 CWD successful. "/Archive" is current directory.
> NOOP
> 200 OK
> CWD
> 250 Broken client detected, missing argument to CWD. "/Archive" is current directory.
> RNFR Host.xml
> 550 file/directory not found
> QUIT
> 221 Goodbye
> disconnected.`

Running in Laravel 8 -> ftp log

```> Connected, sending welcome message...
> 220-FileZilla Server version 0.9.43 beta
> 220 ****
> USER ***
> 331 Password required for ***
> PASS ****
> 230 Logged on
> PASV
> 227 Entering Passive Mode (****)
> PWD
> 257 "/" is current directory.
> HELP
> 214-The following commands are recognized:
>    USER   PASS   QUIT   CWD    PWD    PORT   PASV   TYPE
>    LIST   REST   CDUP   RETR   STOR   SIZE   DELE   RMD 
>    MKD    RNFR   RNTO   ABOR   SYST   NOOP   APPE   NLST
>    MDTM   XPWD   XCUP   XMKD   XRMD   NOP    EPSV   EPRT
>    AUTH   ADAT   PBSZ   PROT   FEAT   MODE   OPTS   HELP
>    ALLO   MLST   MLSD   SITE   P@SW   STRU   CLNT   MFMT
>    HASH
> 214 Have a nice day.
> CWD test/Host.xml
> 550 CWD failed. "/test/Host.xml": directory not found.
> NOOP
> 200 OK
> TYPE A
> 200 Type set to A
> LIST -A test/Host.xml
> 150 Opening data channel for directory listing of "/test/Host.xml"
> 226 Successfully transferred "/test/Host.xml"
> NOOP
> 200 OK
> CWD test/Archive/Host.xml
> 550 CWD failed. "/test/Archive/Host.xml": directory not found.
> NOOP
> 200 OK
> PASV
> 227 Entering Passive Mode (10,12,128,70,244,228)
> LIST -A test/Archive/Host.xml
> 550 Directory not found.
> NOOP
> 200 OK
> RNFR test/Host.xml
> 350 File exists, ready for destination name.
> RNTO test/Archive/Host.xml
> 250 file renamed successfully
> QUIT
> 221 Goodbye
> disconnected.`
driesvints commented 2 years ago

Hey there,

Can you first please try one of the support channels below? If you can actually identify this as a bug, feel free to open up a new issue with a link to the original one and we'll gladly help you out.

Thanks!

bArraxas commented 1 day ago

Exactly the same problem but I think everybody can understand where is the problem with this simple log : 😉

local.DEBUG: 🟢 app/Affaire.php
local.DEBUG: 🟢 app/AffaireActe.php
local.DEBUG: 🟢 app/FicheTravailKeyword.php
local.DEBUG: 🟢 app/Gardiennage.php
local.DEBUG: 🔴 app/Http/Controllers/VehiculeController.php
local.DEBUG: 🔴 app/Http/Kernel.php
local.DEBUG: 🔴 app/Http/Middleware/TraceActivity.php
local.DEBUG: 🔴 app/Http/Middleware/TrustProxies.php
local.DEBUG: 🔴 app/Http/Requests/SocieteRequest.php
local.DEBUG: 🟢 app/RVT.php
local.DEBUG: 🟢 app/Societe.php
local.DEBUG: 🟢 app/SocieteKeyword.php
local.DEBUG: 🟢 app/SocieteTarif.php
local.DEBUG: 🟢 app/Vehicule.php
local.DEBUG: 🔴 app/Vues/VueMeuble.php
local.DEBUG: 🔴 app/Vues/VueSociete.php
local.DEBUG: 🔴 bootstrap/cache/packages.php
local.DEBUG: 🔴 bootstrap/cache/services.php
local.DEBUG: 🟢 config/filesystems.php
local.DEBUG: 🔴 public/css/app.css
local.DEBUG: 🔴 public/js/app.js
local.DEBUG: 🔴 public/js/manifest.js
local.DEBUG: 🔴 public/js/vendor.js
local.DEBUG: 🟢 public/maintenance.html

When I analyse the security access on FTP, I found "0755" for all sub directory and "0644" for all files.

The question is why lavarel 9 refuse to write while laravel 8 allowed it ? 🤔

And the 1 million dollars question : "How solve this problem ?"

Thanks for your help.

EDIT : I precise the app directory had too "0755". In fact it's like if "Storage::disk('ftp')->put was blocked in "app" folder and dont care new paths. It's like if the "put" method works in relative mode at place of absolute mode.

bArraxas commented 1 day ago

My solution, copy "require" and "require-dev" from this link : https://github.com/laravel/laravel/blob/10.x/composer.json And then run "composer update". And then install one by one others dependencies when adding parameter "-w" is necessary. Exemple "beyondcode/laravel-websockets" is not supported in lavavel 10, so run "composer require beyondcode/laravel-websockets -w". And then as by miracacle the same code "Storage::disk('ftp')->put" will work 😎