[英]transfer files from ssh server directly to client
i have a ssh server which is use to store my files online. 我有一个SSH服务器,用于在线存储我的文件。 i need to make those file available for download easily so i am using paramiko library to connect to the ssh server (from my python script), it then lists files and displays on the webpage.
我需要使这些文件易于下载,因此我正在使用paramiko库连接到ssh服务器(从我的python脚本开始),然后列出文件并显示在网页上。 the problem is that i dont want to download the files to the web server's disk (dont have enough space) then send them to the clients , instead do something like read the file and spit it like it can be done in php.
问题是我不想将文件下载到Web服务器的磁盘上(没有足够的空间),然后将其发送给客户端,而不是像读取文件并像在php中一样将其吐出。
something like this in python 像这样的Python
<?php
// your file to upload
$file = '2007_SalaryReport.pdf';
header("Expires: 0");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Content-type: application/pdf");
// tell file size
header('Content-length: '.filesize($file));
// set file name
header('Content-disposition: attachment; filename='.basename($file));
readfile($file);
// Exit script. So that no useless data is output-ed.
exit;
?>
Not a programmer's answer: instead of paramiko, mount the directory with documents with sshfs
and serve the documents as if they were on the local file system 不是程序员的答案:代替paramiko,使用
sshfs
装载带有文件的目录,并像处理本地文件系统一样处理文件
http://fuse.sourceforge.net/sshfs.html http://fuse.sourceforge.net/sshfs.html
A cgi script generates output on stdout
which is delivered to the webserver. 一个cgi脚本在
stdout
上生成输出,并将其输出到Web服务器。 The output starts with header lines, one blank line (as a separator) and then the content. 输出从标题行开始,一个空白行(作为分隔符),然后是内容。
So you have to change the header()
calls to print
statements. 因此,您必须将
header()
调用更改为print
语句。 And readfile($file)
should be replaced by 并且
readfile($file)
应该替换为
print
print open("2007_SalaryReport.pdf","rb").read()
See http://en.wikipedia.org/wiki/Common_Gateway_Interface 参见http://en.wikipedia.org/wiki/Common_Gateway_Interface
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.