Black Rabbit
Новичок
Многопоточная закачка по ftp
Здравствуйте!
Есть такая задача- надо организовать скачивание файлов по фтп с поддержкой закачки так, чтобы скрывать реальный путь до файлов от пользователей. Серверов несколько, анонимный доступ закрыт
Делаю через скрипт следующим образом:
$ftp = ftp_connect($server['url']);
ftp_login($ftp,$server['log'],$server['pass']);
$fileSize =ftp_size($ftp,$download[1]);
if(isset($_SERVER["HTTP_RANGE"]))
{
preg_match ("/bytes=(\d+)-/", $_SERVER["HTTP_RANGE"], $m);
$range=intval($m[1]);
$contentSize = $fileSize - $range;
$p1 = $fileSize-$contentSize;
$p2 = $fileSize-1;
$p3 = $fileSize;
$REST_RANGE=$range-($fileSize -1)."/".$fileSize;
header ("HTTP/1.1 206 Partial Content");
header ("Date: " . getGMTDateTime());
header ("X-Powered-By: PHP/" . phpversion());
header ("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
header ("Cache-Control: None");
header ("Pragma: no-cache");
header ("Accept-Ranges: bytes");
header ("Content-Type: application/force-download");
header ("Content-Disposition: attachment; filename=\"".basename($download[1])."\"");
header ("Content-Range: bytes " . $p1 . "-" . $p2 . "/" . $p3);
header ("Content-Length: " . $contentSize);
header ("Content-Type: application/octet-stream");
header ("Proxy-Connection: close");
header ("");
}
else
{
$range=0;
$contentSize = $fileSize;
header ("HTTP/1.1 200 OK");
header ("Date: " . getGMTDateTime ());
header ("X-Powered-By: PHP/" . phpversion());
header ("Content-Type: application/force-download");
header ("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
header ("Cache-Control: None");
header ("Pragma: no-cache");
header ("Accept-Ranges: bytes");
header ("Content-Disposition: attachment; filename=\"".basename($download[1])."\"");
header ("Content-Length: " . $contentSize);
header ("Age: 0");
header ("Content-Type: application/octet-stream");
header ("Proxy-Connection: close");
header ("");
}
$out = fopen("php://output", "w");
ftp_fget($ftp, $out, $download[1], FTP_BINARY,$range);
ftp_close($ftp);
fclose($out);
exit();
При скачивании программами вроде Download Master в многопоточном режиме файлы бьются.
Существует ли способ организовать отдачу файлов в несколько потоков без ущерба для безопасности?
Здравствуйте!
Есть такая задача- надо организовать скачивание файлов по фтп с поддержкой закачки так, чтобы скрывать реальный путь до файлов от пользователей. Серверов несколько, анонимный доступ закрыт
Делаю через скрипт следующим образом:
$ftp = ftp_connect($server['url']);
ftp_login($ftp,$server['log'],$server['pass']);
$fileSize =ftp_size($ftp,$download[1]);
if(isset($_SERVER["HTTP_RANGE"]))
{
preg_match ("/bytes=(\d+)-/", $_SERVER["HTTP_RANGE"], $m);
$range=intval($m[1]);
$contentSize = $fileSize - $range;
$p1 = $fileSize-$contentSize;
$p2 = $fileSize-1;
$p3 = $fileSize;
$REST_RANGE=$range-($fileSize -1)."/".$fileSize;
header ("HTTP/1.1 206 Partial Content");
header ("Date: " . getGMTDateTime());
header ("X-Powered-By: PHP/" . phpversion());
header ("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
header ("Cache-Control: None");
header ("Pragma: no-cache");
header ("Accept-Ranges: bytes");
header ("Content-Type: application/force-download");
header ("Content-Disposition: attachment; filename=\"".basename($download[1])."\"");
header ("Content-Range: bytes " . $p1 . "-" . $p2 . "/" . $p3);
header ("Content-Length: " . $contentSize);
header ("Content-Type: application/octet-stream");
header ("Proxy-Connection: close");
header ("");
}
else
{
$range=0;
$contentSize = $fileSize;
header ("HTTP/1.1 200 OK");
header ("Date: " . getGMTDateTime ());
header ("X-Powered-By: PHP/" . phpversion());
header ("Content-Type: application/force-download");
header ("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
header ("Cache-Control: None");
header ("Pragma: no-cache");
header ("Accept-Ranges: bytes");
header ("Content-Disposition: attachment; filename=\"".basename($download[1])."\"");
header ("Content-Length: " . $contentSize);
header ("Age: 0");
header ("Content-Type: application/octet-stream");
header ("Proxy-Connection: close");
header ("");
}
$out = fopen("php://output", "w");
ftp_fget($ftp, $out, $download[1], FTP_BINARY,$range);
ftp_close($ftp);
fclose($out);
exit();
При скачивании программами вроде Download Master в многопоточном режиме файлы бьются.
Существует ли способ организовать отдачу файлов в несколько потоков без ущерба для безопасности?