2011-09-21 2 views
0

저는 온라인으로 파일을 저장하는 데 사용되는 ssh 서버를 가지고 있습니다. 그 파일을 쉽게 다운로드 할 수 있도록해야합니다. 그래서 paramiko 라이브러리를 사용하여 (내 파이썬 스크립트에서) ssh 서버에 연결하고, 파일 목록과 웹 페이지에 표시합니다. 문제는 내가 웹 서버의 디스크에 파일을 다운로드하고 싶지 않다는 것이다. (충분한 공간이 없다.) 그런 다음 클라이언트에게 보낸다. 대신 파일을 읽고 PHP에서 할 수있는 것처럼 침을 뱉어 라. 파이썬에서이 같은ssh 서버에서 클라이언트로 직접 파일을 전송합니다.

뭔가

<?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; 
?> 
+1

대답은 사용하는 웹 프레임 워크에 따라 다릅니다. Python에는 differen API가있는 몇 가지 다른 웹 프레임 워크가 있습니다. – rocksportrocker

+0

나는 현재 일반 cgi 스크립트를 시도하고 있지만 webapp2, web.py 및 django에 열려 있습니다. – voldyman

답변

1

하지 프로그래머의 답변을 참조

print 
print open("2007_SalaryReport.pdf","rb").read() 

로 대체해야합니다, 대신 paramiko의 sshfs와 문서와 디렉토리를 마운트가 로컬 파일 시스템에있는 것처럼 문서를 제공

http://fuse.sourceforge.net/sshfs.html

+0

웹 서버에 루트가 아니기 때문에 소프트웨어를 설치할 수 없습니다 (무료 계정) – voldyman

관련 문제