获取“FTP服务器报告550无法获取文件大小”。在fopen中使用FTP URL时 [英] Getting "FTP server reports 550 Could not get file size." when using FTP URL in fopen

查看:2985
本文介绍了获取“FTP服务器报告550无法获取文件大小”。在fopen中使用FTP URL时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想读一个远程ftp服务器上的文件给一个变量。我尝试阅读地址

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

fopen("ftp://user:pass@localhost/filetoread");

$contents = file_get_contents('ftp://ftpuser:123456789@localhost/file.conf');
echo $contents;

两者都不起作用。我也尝试直接发送 GET 请求到URL,这也不起作用。如何在不下载的情况下阅读FTP文件?

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?

我检查了php警告,其中说:

I checked the php warning which says:


PHP警告:file_get_contents( ftp://...@localhost/file.conf ):无法打开流:FTP服务器报告550无法获取文件大小。

位于/var/www/html/api/listfolder.php第2行

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

我确定该文件存在

推荐答案

PHP FTP URL wrapper 似乎需要FTP SIZE 命令,您的FTP服务器不支持。

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

使用 ftp_fget 改为:

Use the ftp_fget instead:

$conn_id = ftp_connect('hostname');

ftp_login($conn_id, 'username', 'password');

$h = fopen('php://temp', 'r+');

ftp_fget($conn_id, $h, '/path/to/file', FTP_BINARY, 0);

$fstats = fstat($h);
fseek($h, 0);
$contents = fread($h, $fstats['size']); 

fclose($h);
ftp_close($conn_id);

请参阅 PHP:如何从FTP服务器读取.txt文件到变量中?

这篇关于获取“FTP服务器报告550无法获取文件大小”。在fopen中使用FTP URL时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆