简体   繁体   English

将文件从SSH服务器直接传输到客户端

[英]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.

相关问题 需要将多个文件从客户端传输到服务器 - Need to transfer multiple files from client to server 如何使用python脚本将文件从客户端传输到服务器计算机? - How to Transfer Files from Client to Server Computer by using python script? 将文件直接从表单发送到远程服务器 - Send files from form directly to remote server 是否可以使用python将文本文件从服务器传输到客户端? - Is it possible to transfer a text file from server to client using python? 将数据从PHP(客户端)传输到Python脚本(服务器) - Transfer data from PHP(client) to a Python script(server) 如何加快从客户端到服务器的图像传输 - How to speed up transfer of images from client to server 从客户端到服务器的扭曲图像传输导致格式错误 - twisted image transfer from client to server gives bad format error 当我从Linux机器尝试到Windows ssh客户端服务器时,来自pexpect(pxssh)的SSH失败 - SSH from pexpect (pxssh) fails when I try from a linux machine to a windows ssh client server 如何在paramiko的ssh连接中将文件传输到ssh服务器? - How to transfer a file to ssh server in an ssh-connection made by paramiko? 使用 SFTP 将文件从 AWS S3 传输到 Unix 服务器 - Transfer files from AWS S3 to Unix Server using SFTP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM