Hello.

It is impossible for the script to download files from an "alien" (not hosting) ftp-server.

Tried through

1) CURL

2) file_put_content + file_get_content

3) copy

4) ftp_get

For some reason, it turns out to download files from an ftp-hosting, but you cannot download from third-party ftp (the script takes about a minute, without errors, and creates an empty file).

Maybe these are some limitations / features on the hosting?

  • why did you get into a "foreign server"? what are we stealing? - Arsen
  • - the producer lays out his upload (for clients) on ftp .. and not through the usual http - Artyom
  • and the script is started with under the apache / nginksa? - KoVadim
  • The script runs through hosting (by URL). Your local ftp-hosting works by all means, no ftp-needed server. Maybe there are some variables, where you can make sure that some setting for the service works in a limited mode? - Артём
  • From another hosting, everything works, from the right one - no. - Artem

1 answer 1

For this task you need to use the function ftp_get

 <?php $LocalfileName = 'file.php'; $ServerfileName = 'file.php'; $ftp_server="server.ru"; $ftp_username="ftp логин"; $ftp_userpass="ftp пароль"; $conn = ftp_connect($ftp_server); $login_result = ftp_login($conn, $ftp_username, $ftp_userpass); if (ftp_get($conn, $LocalfileName, $ServerfileName, FTP_BINARY)) { echo "Файл $LocalfileName \n"; } else { echo "Ошибка\n"; } ftp_close($conn); ?> 
  • Thank you, but also tried it (the result is similar). Although I didn’t play it with the 3rd parameter, it may somehow be connected with it - Artyom
  • read the documentation)) php.net/manual/ru/function.ftp-get.php - Arsen
  • I twisted ftp_get a few more times - it didn't help. Falls on the connection. Either the case is in some limitations of the hosting server, or in the restrictions imposed by the ftp server owner. - Артём
  • We tried with another hosting - everything works (the guess was justified). The question remains - what is wrong with the old hosting? - Artem
  • On the hosting, the possibility of working ftp_connect is disabled, etc., write to the support, they activate. - Arsen