def upload_to(host, filename, port=7777):
"""
Simple method to upload a file into NGAS
"""
with contextlib.closing(httplib.HTTPConnection(host, port)) as conn:
conn.putrequest('POST', '/QARCHIVE?filename=%s' % (urllib2.quote(os.path.basename(filename)),) )
conn.putheader('Content-Length', os.stat(filename).st_size)
conn.endheaders()
with open(filename) as f:
for data in iter(functools.partial(f.read, 4096), ''):
conn.send(data)
r = conn.getresponse()
if r.status != httplib.OK:
raise Exception("Error while QARCHIVE-ing %s to %s:%d:\nStatus: %d\n%s\n\n%s" % (filename, conn.host, conn.port, r.status, r.msg, r.read()))
else:
success("{0} successfully archived to {1}!".format(filename, host))
评论列表
文章目录