Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError, ftp_chdir(): Argument #2 ($directory) must be of type string, null given in FtpAdapter.php:102 #1825

Open
rayanlevert opened this issue Oct 30, 2024 · 0 comments

Comments

@rayanlevert
Copy link

Bug Report

Q A
Flysystem Version 3.24.0
Adapter Name Ftp
Adapter version 3.24.0

Summary

Hello ! There is a TypeError encountered in your source code, using the FtpAdapter.

When we connect one time to the FTP and we try to ->write(), an exception is thrown because the root directory is not present, not a problem for that. (Unable to resolve connection root. It does not seem to exist:).

When we try to ->write() a second time with the same instance, there is the TypeError, because the connection was successful but you could not set the rootDirectory which is null by default property the first time.

How to reproduce

Make sure the root directory passed is not created on the FTP.

$adapter = new Filesystem(new FtpAdapter());

try {
    // Exception, Unable to resolve connection root..
    $adapter->write();
} catch (FilesystemException) {
    // TypeError
    $adapter->write();
}

From what I've seen in the source code (FtpAdapter), after the first call, ->connection becomes a resource but throws an exception when you try to set ->rootDirectory.
The second call, if ( !$this->hasFtpConnection()) { you don't go in this condition, and continues to line 102 when you call ftp_chdir with $this->rootDirectory to null.

Full trace of the Error here.

PHP Fatal error:  Uncaught TypeError: ftp_chdir(): Argument #2 ($directory) must be of type string, null given in /data/apps/app_paper/vendor/league/flysystem-ftp/FtpAdapter.php:102
Stack trace:
#0 /data/apps/app_paper/vendor/league/flysystem-ftp/FtpAdapter.php(102): ftp_chdir()
#1 /data/apps/app_paper/vendor/league/flysystem-ftp/FtpAdapter.php(661): League\Flysystem\Ftp\FtpAdapter->connection()
#2 /data/apps/app_paper/vendor/league/flysystem-ftp/FtpAdapter.php(162): League\Flysystem\Ftp\FtpAdapter->prefixer()
#3 /data/apps/app_paper/vendor/league/flysystem-ftp/FtpAdapter.php(148): League\Flysystem\Ftp\FtpAdapter->writeStream()
#4 /data/apps/app_paper/vendor/league/flysystem/src/Filesystem.php(55): League\Flysystem\Ftp\FtpAdapter->write()
#5 /data/apps/app_paper/src/Tasks/EnvoiTask.php(191): League\Flysystem\Filesystem->write()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant