У меня есть скрипт, который собирает данные через FTP и отлично работает.Проблема в том, что вы должны указать имя файла, который вы хотите загрузить.
Пример: https://mydomain/downloadFile?file=folder/file1.csv
Что я хочу сделать, это сохранить все файлы впапка без указания имени файла.
Функция:
function downloadFile(Request $request) {
$file = $request->get('file');
if(!$file) {
return Response::json('please provide valid path', 400);
}
$fileName = basename($file);
$ftp = Storage::createFtpDriver([
'host' => 'ftp.site.com',
'username' => 'email.com',
'password' => 'password',
'port' => '21', // your ftp port
'timeout' => '30', // timeout setting
]);
$filecontent = $ftp->get($file); // read file content
// save file.
Storage::put('file1.csv', $filecontent);
// download file.
return Response::make($filecontent, '200', array(
'Content-Type' => 'application/octet-stream',
'Content-Disposition' => 'attachment; filename="'.$fileName.'"'
));
}