I’m writing to StackOverflow about a problem I’m having downloading a file from a distant server using SFTP.
I can upload and delete a file, but I cannot download a file.
Here is my code for download :
$document = Storage::disk('sftp')->download("test2.xlsx");
dd($document) ;
dd($document) return :
From here I don’t know what to do. I tried several things, but no result.
I Want to download it with my browser Firefox for example.
Does I need to store it on my local server before downloading, like
Storage::disk('local')->put('path/to/store/'.$document, file_get_contents($document));
How do I use the information returned by the request? Is an object?
Thank you for your help.
1
I cannot download many files at the same time.
I must download one file at a time.
Here is the solution for downloading one file at a time.
On HTML with Vue.js:
<td colspan="2" style="cursor:pointer;" title="document">
<a :href="'/downloadSFTP/' + document.id"><span v-
html="getDocumentIcon(document.Extension)"></span>
</a>
</td>
On routes file:
Route::get('/downloadSFTP/{id}', 'SFTPController@download')
->name('sftp.download');
On Controller:
public function download($id)
{
if(Auth::user()->isAdmin())
{
$error = Lang::get('form')['non-existent-document'];
$documents = Documents::find($id);
$tmpDocs = explode("/",$documents->Path);
$documentsName = $tmpDocs[1].".".$documents->Extension;
return Storage::disk('sftp')->download($documentsName);
}
else
{
return view('errors.403');
}
}
If someone has a solution for downloading many files simultaneously, thank you for your tips.
I’ve heard that We will do it with a promise.