Laravel download files via FTP

This post is going to be about downloading files from the remote server via FTP mechanism in your Laravel application.

Let’s create a controller called DownloadController.php

Now let’s inform about this controller to routes/web.php

That’s it. Now point your browser to http://yourhost.com/downloadFile?file=remote_path/fileName.png.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

0 0 vote
Article Rating
Subscribe
Notify of
guest
7 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Ивин Сергей
Ивин Сергей
2 years ago

Exactly what I need. Thanks!

Yadi
Yadi
1 year ago

how to return to web view from remote ftp? not download.

arjun
1 year ago
Reply to  Yadi

just have to set proper headers. Or download them to local system and put in the web server.

Matthew Richter
Matthew Richter
1 year ago

Hi, how would i return all files in the ftp folder , not just one. Can you add that solution?

theefer
theefer
10 months ago

foreach( Storage::disk(‘ftp’)->glob(‘/’){
// do save code to location
}

anonymous
anonymous
1 year ago

I tried it but I got FileNotFoundException, while the file was uploaded to the ftp server and its name exists in $ftp->files().

I’m using Laravel 5.7

theefer
theefer
10 months ago

Instead of


return Response::make($filecontent, '200', array(
'Content-Type' => 'application/octet-stream',
'Content-Disposition' => 'attachment; filename="'.$fileName.'"'
));


is used this to store the downloaded file to disk:


Storage::drive("diskName")->put($storage_path . $fileName, $file_data);

DMCA.com Protection Status
7
0
Would love your thoughts, please comment.x
()
x