Module FileServer
[hide private]
[frames] | no frames]

Source Code for Module FileServer

 1  # Copyright (C) 2005, 2006 Joint Institute for VLBI in Europe 
 2  # 
 3  # This program is free software; you can redistribute it and/or modify 
 4  # it under the terms of the GNU General Public License as published by 
 5  # the Free Software Foundation; either version 2 of the License, or 
 6  # (at your option) any later version. 
 7  # 
 8  # This program is distributed in the hope that it will be useful, 
 9  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
10  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
11  # GNU General Public License for more details. 
12   
13  # You should have received a copy of the GNU General Public License 
14  # along with this program; if not, write to the Free Software 
15  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
16   
17  """ 
18  This server provides a simple/stupid way to transfer files to /tmp on a 
19  remote machine, without troubling with pesky user authentication &cet. 
20   
21  """ 
22   
23  import os 
24  import sys 
25  import SocketServer 
26   
27 -class FileServer(SocketServer.ForkingMixIn, SocketServer.TCPServer) : pass
28
29 -class FileWriter(SocketServer.BaseRequestHandler) :
30 dir = "/tmp"
31 - def handle(self) :
32 copy = open(os.tempnam(self.dir),"w") 33 self.request.send(copy.name) 34 while True: 35 data = self.request.recv(65536) 36 if not data : break 37 copy.write(data) 38 copy.close()
39 40 if __name__ == "__main__" : 41 try : 42 if (len(sys.argv) > 1) : 43 server = FileServer(('',8001),FileWriter(sys.argv[1])) 44 else : 45 server = FileServer(('',8001),FileWriter) 46 server.serve_forever() 47 except(KeyboardInterrupt) : 48 print "FileServer exiting. Later!" 49