Skip to content
Advertisement

Getting “FTP server reports 550 Could not get file size.” when using FTP URL in fopen

I want to read a file which is on a remote ftp server to a variable. I tried reading with address

JavaScript

and

JavaScript

Neither does work. I also tried to send directly GET request to the URL which also doesn’t work. How can I read the FTP file without downloading?

I checked the php warning which says:

PHP Warning: file_get_contents(ftp://…@localhost/file.conf): failed to open stream: FTP server reports 550 Could not get file size.
in /var/www/html/api/listfolder.php on line 2

I’m sure that the file exists

Advertisement

Answer

The PHP FTP URL wrapper seems to require FTP SIZE command, what your FTP server does not support.

Use the ftp_fget instead:

JavaScript

(add error handling)

See PHP: How do I read a .txt file from FTP server into a variable?

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement