# http_put.py # # This is a very quick example on how to upload a file to # an ftp server using a squid proxy. This probably works # in other HTTP proxies, but i haven't tried out. # # Inspiration sources: # # Is there a general or Squid specific FTP Proxy Protocol Spec? # http://www.squid-cache.org/mail-archive/squid-dev/200107/0024.html # # QuickPut - An HTTP PUT Tool in Python # http://infomesh.net/2001/QuickPut/ # # Squid # http://www.squid-cache.org/ # import httplib import StringIO import base64 url = 'ftp://:@/' fn = '' proxy_addr = 'proxy' proxy_port = 8080 debug = 0 # grab file contents and size f = open( fn, 'rb' ) b = StringIO.StringIO( f.read() ) f.close() s = len( b.getvalue() ) # request print "Request:" print print "PUT %s%s HTTP/1.0" % ( url, fn ) print "Content-Length: %d" % ( s ) print # send file h = httplib.HTTP( proxy_addr, proxy_port ) h.set_debuglevel( debug ) h.putrequest( 'PUT', url + fn, True, True ) h.putheader( 'Content-Length', str(s) ) h.putheader( 'Connection', 'Keep-Alive' ) h.endheaders() h.send( b.getvalue() ) errcode, errmsg, headers = h.getreply() h.close() # reply print "%s %s" % ( errcode, errmsg ) print headers print