C
C
CeBePHblY2016-03-01 21:40:26
PHP
CeBePHblY, 2016-03-01 21:40:26

Why doesn't file_get_contents get file contents via ftp?

An FTP server is configured on the Ubuntu server. Everything is perfectly connected through the client. On the same server there is a site, it has a file ftp.php with the following content;

<?php
$ftphost        = '91.2**.*11.**';
$ftpport        = '21';
$ftpuser        = 'user';
$ftppasswd      = 'o$ofrJhjky4K+/`4';
$file = 'otchet.txt';
// Папка, которую нужно выводить
$folder         = 'docs/otchet/2016';
$content = file_get_contents('ftp://'.$ftpuser.':'.$ftppasswd.'@'.$ftphost.'/'.$folder.'/'.$file);
echo ($content);
?>

But file_get_contents doesn't get the content. I inserted both localhost and 127.0.0.1 into ftphost, but still does not receive the content. The FTP server logs say that the client connected without errors. And in the php logs there is such an error:
file_get_contents: failed to open stream
Tell me what's wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Tikhomirov, 2016-03-01
@CeBePHblY

The main mistake of developers is that they only know file_get_contents and try to do everything with it, up to cURL. Use standard tools for working with FTP: php.net/manual/ru/book.ftp.php , there is error control, and certificates, and everything you need. And yes, unlike file_get_contents they will say what is wrong.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question