Request via FTP and return file via HTTP

Asked

Viewed 107 times

0

I am developing a blog and would like to use resources from another server via FTP. In order to share some of these files in my posts I imagined that it would be possible to connect the FTP within PHP and return the desired file to the user, without having to copy to my PHP server from the blog. Hence the questions: would PHP need to download the whole file before returning it? Which method should I use from the library nicolab/php-ftp-client to achieve such an effect?

An example more or less than I think it would be:

Route::get('files/{id_artigo}/{arquivo}', 'FTPController@pegarArquivo');

And within the method, that would be the interesting part, but I don’t know how to proceed:

$ftp = FTPClient();
$ftp->connect($host);
$ftp->login($user, $passwd);
// Abaixo o dummyMethod() deveria
// pegar o arquivo e armazenar em $file
// NOTA: $nome é o nome do arquivo 
$file = $ftp->dummyMethod($nome);
return $file;

1 answer

0

  • Is it safe to do that? I’ll try to intercept the request here to see what happens

  • The problem is that I need to do it this way because the other server does not provide http connections

  • You must configure a user only for the public files that you want to make available, you will not leave your admin user in the url. Managed to intercept?

  • @Andersonsantos as it was solved?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.