0

i have a ssh server which is use to store my files online. 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. 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.

something like this in 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;
?>
2
  • 1
    the answer depends on the web framework you use. Python has several different web framkeworks with differen APIs. Commented Sep 21, 2011 at 11:15
  • i am currently trying plain cgi script but am open to webapp2 ,web.py and django.. Commented Sep 21, 2011 at 11:33

2 Answers 2

1

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

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

Sign up to request clarification or add additional context in comments.

1 Comment

i am not root on the web server so cant install software ( free account )
0

A cgi script generates output on stdout which is delivered to the webserver. 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. And readfile($file) should be replaced by

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

See http://en.wikipedia.org/wiki/Common_Gateway_Interface

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.