-
Notifications
You must be signed in to change notification settings - Fork 0
/
httpclient.py
72 lines (55 loc) · 2.02 KB
/
httpclient.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# -*- coding: utf-8 -*-
"""
Created on Thu May 28 08:21:56 2015
@author: mininet
"""
#import time
#import os
#import signal
import argparse
#import sys
from socket import *
import subprocess
import shlex
def call_wget(server, filename):
# call(["wget", "-O", "-", "%s/%s" % (server, filename), "|", "md5sum"])
args = shlex.split("wget -O tmp_file %s/%s" % (server, filename))
wget = subprocess.call(args)
md5sum = subprocess.call(shlex.split("md5sum tmp_file"))
subprocess.call(shlex.split("rm tmp_file"))
def startRealDownload(server, filename):
print "After every download, md5sum will calculate the md5 hash."
print "This will show you the correctness of the file transfer even if the link quality is bad."
print ""
raw_input("Press Enter to download file %s from server %s. " % (filename, server))
redownload = True
while redownload == True:
call_wget(server, filename)
again = raw_input("Download complete. Download again? (y/N) ")
if not(again == "y" or again == "Y"):
redownload = False
raw_input("Demo is over. Press Enter to close window. ")
return 0
if __name__ == '__main__':
#setLogLevel( 'info' )
def type_port(x):
x = int(x)
if x < 1 or x > 65535:
raise argparse.ArgumentTypeError(
"Port number has to be greater than 1 and less than 65535.")
return x
description = ("Download a file from a HTTP server")
parser = argparse.ArgumentParser(description=description)
parser.add_argument("-s",
"--server",
help="The IP of the http server. "
"(Default: '10.0.0.1')",
default="10.0.0.1")
parser.add_argument("-f",
"--file",
help="file name",
type=str,
required=True)
args = parser.parse_args()
exit(startRealDownload(server=args.server,
filename=args.file))