如何在不使用主机带宽传输的情况下从另一个 FTP 主机读取文件
How to read file from another FTP host without use host bandwidth transfer
我有一个存储数据的主机和一个下载主机(这个主机没有数据库)。我想从 下载主机 存储主机 中读取文件并将其提供给用户下载,但我不想使用每月带宽传输存储主机当用户下载文件并且只使用下载主机带宽传输。
我知道的有两种方式:
ftp_get
下载文件并保存到本地文件,然后设置header
下载。我不想使用这种方式,因为在商店主机中下载文件。
// in store host
$local_file = 'app.apk';
$ftp_file = '/uploads/2015/06/1eb6a628c60bb69a6b6092d03e252c29.apk';
// download file and save it in local
ftp_get($conn_id , $local_file, $ftp_file, FTP_BINARY);
$file_name = 'app.apk';
$file_size = filesize($local_file);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $file_name);
header('Content-Transfer-Encoding: binary');
header('Connection: Keep-Alive');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . $file_size);
readfile($local_file);
我不知道 file_get_contents
在用户下载文件时是否使用 存储主机 的带宽传输。
// in store host
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $file_name);
header('Content-Transfer-Encoding: binary');
header('Connection: Keep-Alive');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . $file_size);
// readfile($local_file);
$c = file_get_contents('ftp://login:pass@download-host.com/uploads/2015/06/app.apk');
echo $c;
我不想在商店主机中使用带宽传输;我可以使用哪种方式?方式 2 还是其他方式?
如果不向客户端提供下载所需的所有信息 ("download link"),则无法将内容从 "download host" 直接下载到客户端。
如果需要对客户端隐藏下载信息,需要在"store host"上下载文件,然后转发给客户端。因此,您正在消耗 "store host" 的带宽数据。您使用什么技术、协议或功能并不重要。而且 ftp_get
和 file_get_contents("ftp://...")
无论如何都使用相同的代码。
简单地说,没有办法既对客户端隐藏下载信息又不使用"store host"的带宽数据。
我有一个存储数据的主机和一个下载主机(这个主机没有数据库)。我想从 下载主机 存储主机 中读取文件并将其提供给用户下载,但我不想使用每月带宽传输存储主机当用户下载文件并且只使用下载主机带宽传输。
我知道的有两种方式:
ftp_get
下载文件并保存到本地文件,然后设置header
下载。我不想使用这种方式,因为在商店主机中下载文件。// in store host $local_file = 'app.apk'; $ftp_file = '/uploads/2015/06/1eb6a628c60bb69a6b6092d03e252c29.apk'; // download file and save it in local ftp_get($conn_id , $local_file, $ftp_file, FTP_BINARY); $file_name = 'app.apk'; $file_size = filesize($local_file); header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . $file_name); header('Content-Transfer-Encoding: binary'); header('Connection: Keep-Alive'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . $file_size); readfile($local_file);
我不知道
file_get_contents
在用户下载文件时是否使用 存储主机 的带宽传输。// in store host header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . $file_name); header('Content-Transfer-Encoding: binary'); header('Connection: Keep-Alive'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . $file_size); // readfile($local_file); $c = file_get_contents('ftp://login:pass@download-host.com/uploads/2015/06/app.apk'); echo $c;
我不想在商店主机中使用带宽传输;我可以使用哪种方式?方式 2 还是其他方式?
如果不向客户端提供下载所需的所有信息 ("download link"),则无法将内容从 "download host" 直接下载到客户端。
如果需要对客户端隐藏下载信息,需要在"store host"上下载文件,然后转发给客户端。因此,您正在消耗 "store host" 的带宽数据。您使用什么技术、协议或功能并不重要。而且 ftp_get
和 file_get_contents("ftp://...")
无论如何都使用相同的代码。
简单地说,没有办法既对客户端隐藏下载信息又不使用"store host"的带宽数据。