저는 온라인으로 파일을 저장하는 데 사용되는 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;
?>
대답은 사용하는 웹 프레임 워크에 따라 다릅니다. Python에는 differen API가있는 몇 가지 다른 웹 프레임 워크가 있습니다. – rocksportrocker
나는 현재 일반 cgi 스크립트를 시도하고 있지만 webapp2, web.py 및 django에 열려 있습니다. – voldyman